|
|
@ -101,7 +101,7 @@ func (s *ExtendedJWT) authenticateAsUser( |
|
|
|
accessTokenClaims authlib.Claims[authlib.AccessTokenClaims], |
|
|
|
accessTokenClaims authlib.Claims[authlib.AccessTokenClaims], |
|
|
|
) (*authn.Identity, error) { |
|
|
|
) (*authn.Identity, error) { |
|
|
|
// Only allow id tokens signed for namespace configured for this instance.
|
|
|
|
// Only allow id tokens signed for namespace configured for this instance.
|
|
|
|
if allowedNamespace := s.namespaceMapper(s.getDefaultOrgID()); !claims.NamespaceMatches(authlib.NewIdentityClaims(idTokenClaims), allowedNamespace) { |
|
|
|
if allowedNamespace := s.namespaceMapper(s.cfg.DefaultOrgID()); !claims.NamespaceMatches(authlib.NewIdentityClaims(idTokenClaims), allowedNamespace) { |
|
|
|
return nil, errExtJWTDisallowedNamespaceClaim.Errorf("unexpected id token namespace: %s", idTokenClaims.Rest.Namespace) |
|
|
|
return nil, errExtJWTDisallowedNamespaceClaim.Errorf("unexpected id token namespace: %s", idTokenClaims.Rest.Namespace) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -138,7 +138,7 @@ func (s *ExtendedJWT) authenticateAsUser( |
|
|
|
return &authn.Identity{ |
|
|
|
return &authn.Identity{ |
|
|
|
ID: id, |
|
|
|
ID: id, |
|
|
|
Type: t, |
|
|
|
Type: t, |
|
|
|
OrgID: s.getDefaultOrgID(), |
|
|
|
OrgID: s.cfg.DefaultOrgID(), |
|
|
|
AccessTokenClaims: &accessTokenClaims, |
|
|
|
AccessTokenClaims: &accessTokenClaims, |
|
|
|
IDTokenClaims: &idTokenClaims, |
|
|
|
IDTokenClaims: &idTokenClaims, |
|
|
|
AuthenticatedBy: login.ExtendedJWTModule, |
|
|
|
AuthenticatedBy: login.ExtendedJWTModule, |
|
|
@ -155,7 +155,7 @@ func (s *ExtendedJWT) authenticateAsUser( |
|
|
|
|
|
|
|
|
|
|
|
func (s *ExtendedJWT) authenticateAsService(accessTokenClaims authlib.Claims[authlib.AccessTokenClaims]) (*authn.Identity, error) { |
|
|
|
func (s *ExtendedJWT) authenticateAsService(accessTokenClaims authlib.Claims[authlib.AccessTokenClaims]) (*authn.Identity, error) { |
|
|
|
// Allow access tokens with that has a wildcard namespace or a namespace matching this instance.
|
|
|
|
// Allow access tokens with that has a wildcard namespace or a namespace matching this instance.
|
|
|
|
if allowedNamespace := s.namespaceMapper(s.getDefaultOrgID()); !claims.NamespaceMatches(authlib.NewAccessClaims(accessTokenClaims), allowedNamespace) { |
|
|
|
if allowedNamespace := s.namespaceMapper(s.cfg.DefaultOrgID()); !claims.NamespaceMatches(authlib.NewAccessClaims(accessTokenClaims), allowedNamespace) { |
|
|
|
return nil, errExtJWTDisallowedNamespaceClaim.Errorf("unexpected access token namespace: %s", accessTokenClaims.Rest.Namespace) |
|
|
|
return nil, errExtJWTDisallowedNamespaceClaim.Errorf("unexpected access token namespace: %s", accessTokenClaims.Rest.Namespace) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -186,7 +186,7 @@ func (s *ExtendedJWT) authenticateAsService(accessTokenClaims authlib.Claims[aut |
|
|
|
ID: id, |
|
|
|
ID: id, |
|
|
|
UID: id, |
|
|
|
UID: id, |
|
|
|
Type: t, |
|
|
|
Type: t, |
|
|
|
OrgID: s.getDefaultOrgID(), |
|
|
|
OrgID: s.cfg.DefaultOrgID(), |
|
|
|
AccessTokenClaims: &accessTokenClaims, |
|
|
|
AccessTokenClaims: &accessTokenClaims, |
|
|
|
IDTokenClaims: nil, |
|
|
|
IDTokenClaims: nil, |
|
|
|
AuthenticatedBy: login.ExtendedJWTModule, |
|
|
|
AuthenticatedBy: login.ExtendedJWTModule, |
|
|
@ -247,11 +247,3 @@ func (s *ExtendedJWT) retrieveAuthorizationToken(httpRequest *http.Request) stri |
|
|
|
// Strip the 'Bearer' prefix if it exists.
|
|
|
|
// Strip the 'Bearer' prefix if it exists.
|
|
|
|
return strings.TrimPrefix(jwtToken, "Bearer ") |
|
|
|
return strings.TrimPrefix(jwtToken, "Bearer ") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *ExtendedJWT) getDefaultOrgID() int64 { |
|
|
|
|
|
|
|
orgID := int64(1) |
|
|
|
|
|
|
|
if s.cfg.AutoAssignOrg && s.cfg.AutoAssignOrgId > 0 { |
|
|
|
|
|
|
|
orgID = int64(s.cfg.AutoAssignOrgId) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return orgID |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|