Added JWT Auth

Wrote my own JWT auth middleware, since I could not get the go-chi middleware to accept a JWKS instead of a certificate.
This commit is contained in:
Annika Merris 2024-02-10 17:18:22 -05:00
parent ac18b94a86
commit b5ea01729b
12 changed files with 336 additions and 132 deletions

22
helpers/jwtHelpers.go Normal file
View file

@ -0,0 +1,22 @@
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
}