You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Question] How to get path parameter during authorization? JWT audience claim in path for multi-tenant app #2923
I think I figured it out, using a custom Authorizer. You still need to disable the audience claim check when decoding the JWT, but then the Authorizer will check the principal's tenant ID based on the path. Let me know if anyone has any feedback.
typeTenantAuthorizerstruct {
}
funcNewTenantAuthorizer() *TenantAuthorizer {
return&TenantAuthorizer{}
}
func (aTenantAuthorizer) Authorize(req*http.Request, pinterface{}) error {
// cast principal to correct typevarprincipal*models.Principalvarokboolifprincipal, ok=p.(*models.Principal); !ok {
returnerrors.New("invalid principal, expected model.Principal type")
}
// TODO: if principal has SYSTEM/SERVICE scopes then return nil// use regex to get tenantID from `req.URL.Path`// NOTE: all paths must follow the same convention e.g. /tenants/:tenantIDtenantID:=getTenantIDFromRequest(req)
ifprincipal.TenantID!=tenantID {
returnerrors.New("not authenticated")
}
returnnil
}
And in configuration file:
api.APIAuthorizer=auth.NewTenantAuthorizer()
api.OauthSecurityAuth=func(tokenstring, scopes []string) (*models.Principal, error) {
// decode JWT, disable audience claim verification, and return principal
}
Activity
robertdodd commentedon Apr 10, 2023
I think I figured it out, using a custom
Authorizer. You still need to disable theaudienceclaim check when decoding the JWT, but then the Authorizer will check the principal's tenant ID based on the path. Let me know if anyone has any feedback.And in configuration file: