MCPcopy Create free account
hub / github.com/authorizerdev/authorizer / ValidateBrowserSession

Method ValidateBrowserSession

internal/token/auth_token.go:384–419  ·  view source on GitHub ↗
(gc *gin.Context, encryptedSession string)

Source from the content-addressed store, hash-verified

382}
383
384func (p *provider) ValidateBrowserSession(gc *gin.Context, encryptedSession string) (*SessionData, error) {
385 if encryptedSession == "" {
386 return nil, fmt.Errorf(`unauthorized`)
387 }
388
389 decryptedFingerPrint, err := crypto.DecryptAES(p.config.ClientSecret, encryptedSession)
390 if err != nil {
391 return nil, err
392 }
393
394 var res SessionData
395 err = json.Unmarshal([]byte(decryptedFingerPrint), &res)
396 if err != nil {
397 return nil, err
398 }
399
400 sessionStoreKey := res.Subject
401 if res.LoginMethod != "" {
402 sessionStoreKey = res.LoginMethod + ":" + res.Subject
403 }
404 token, err := p.dependencies.MemoryStoreProvider.GetUserSession(sessionStoreKey, constants.TokenTypeSessionToken+"_"+res.Nonce)
405 if token == "" || err != nil {
406 p.dependencies.Log.Debug().Err(err).Msgf("invalid session token: %v, key: %s", err, sessionStoreKey+":"+constants.TokenTypeSessionToken+"_"+res.Nonce)
407 return nil, fmt.Errorf(`unauthorized`)
408 }
409
410 if subtle.ConstantTimeCompare([]byte(encryptedSession), []byte(token)) != 1 {
411 return nil, fmt.Errorf(`unauthorized: invalid nonce`)
412 }
413
414 if res.ExpiresAt <= time.Now().Unix() {
415 return nil, fmt.Errorf(`unauthorized: token expired`)
416 }
417
418 return &res, nil
419}
420
421// CreateIDToken util to create the OIDC ID token JWT, based on user
422// information, roles config and CUSTOM_ACCESS_TOKEN_SCRIPT.

Callers 1

Calls 2

DecryptAESFunction · 0.92
GetUserSessionMethod · 0.65

Tested by

no test coverage detected