claims.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package auth
  2. import (
  3. "github.com/Nerzal/gocloak/v13/pkg/jwx"
  4. "github.com/golang-jwt/jwt/v4"
  5. "github.com/mitchellh/mapstructure"
  6. )
  7. type Claims struct {
  8. Acr string `mapstructure:"acr"`
  9. AllowedOrigins []string `mapstructure:"allowed-origins"`
  10. Aud string `mapstructure:"aud"`
  11. Azp string `mapstructure:"azp"`
  12. EmailVerified bool `mapstructure:"email_verified"`
  13. ExpiresAr int `mapstructure:"exp"`
  14. IssuedAt int `mapstructure:"iat"`
  15. Issuer string `mapstructure:"iss"`
  16. Jti string `mapstructure:"jti"`
  17. Username string `mapstructure:"preferred_username"`
  18. RealmAccess jwx.RealmAccess `mapstructure:"realm_access"`
  19. ResourceAccess jwx.ResourceAccess `mapstructure:"resource_access"`
  20. Scope string `mapstructure:"scope"`
  21. SessionState string `mapstructure:"session_state"`
  22. Sid string `mapstructure:"sid"`
  23. Sub string `mapstructure:"sub"`
  24. Typ string `mapstructure:"typ"`
  25. }
  26. func DecodeClaims(t *jwt.Token) (*Claims, error) {
  27. r := Claims{}
  28. if err := mapstructure.Decode(t.Claims, &r); err != nil {
  29. return nil, err
  30. }
  31. return &r, nil
  32. }