mirror of
https://forgejo.merr.is/annika/isl-api.git
synced 2025-12-11 11:02:03 -05:00
Wrote my own JWT auth middleware, since I could not get the go-chi middleware to accept a JWKS instead of a certificate.
22 lines
511 B
Go
22 lines
511 B
Go
package helpers
|
|
|
|
func JwtHasClaim(claims map[string]interface{}, role string) bool {
|
|
zitadelRoles, ok := claims["urn:zitadel:iam:org:project:roles"].(map[string]interface{})
|
|
if !ok {
|
|
return false
|
|
}
|
|
_, ok = zitadelRoles[role]
|
|
return ok
|
|
}
|
|
|
|
func GetJwtClaim(claims map[string]interface{}, role string) interface{} {
|
|
zitadelRoles, ok := claims["urn:zitadel:iam:org:project:roles"].(map[string]interface{})
|
|
if !ok {
|
|
return nil
|
|
}
|
|
claim, ok := zitadelRoles[role]
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return claim
|
|
}
|