| 306 | } |
| 307 | |
| 308 | func (a *AuthMeta) ExtractCustomClaims(ctx context.Context) (*CustomClaims, error) { |
| 309 | if a == nil { |
| 310 | return &CustomClaims{}, nil |
| 311 | } |
| 312 | // return CustomClaims containing jwt and authvariables. |
| 313 | md, _ := metadata.FromIncomingContext(ctx) |
| 314 | jwtToken := md.Get(string(AuthJwtCtxKey)) |
| 315 | if len(jwtToken) == 0 { |
| 316 | if a.ClosedByDefault { |
| 317 | return &CustomClaims{}, fmt.Errorf("a valid JWT is required but was not provided") |
| 318 | } |
| 319 | return &CustomClaims{}, nil |
| 320 | } |
| 321 | if len(jwtToken) > 1 { |
| 322 | return nil, fmt.Errorf("invalid jwt auth token") |
| 323 | } |
| 324 | return a.validateJWTCustomClaims(jwtToken[0]) |
| 325 | } |
| 326 | |
| 327 | func GetJwtToken(ctx context.Context) string { |
| 328 | md, ok := metadata.FromIncomingContext(ctx) |