func SubjectFromContext(ctx context.Context) (string, error) { args, ok := ctx.Value(authKey).(*authorization) if !ok { return "", errors.Errorf("Could not assert type for %v", ctx.Value(authKey)) } return args.claims.GetSubject(), nil }
func TokenFromContext(ctx context.Context) (*jwt.Token, error) { args, ok := ctx.Value(authKey).(*authorization) if !ok { return nil, errors.Errorf("Could not assert type for %v", ctx.Value(authKey)) } return args.token, nil }
func ContextClient(ctx context.Context) (*http.Client, error) { for _, fn := range contextClientFuncs { c, err := fn(ctx) if err != nil { return nil, err } if c != nil { return c, nil } } if hc, ok := ctx.Value(HTTPClient).(*http.Client); ok { return hc, nil } return http.DefaultClient, nil }
func PoliciesFromContext(ctx context.Context) ([]policy.Policy, error) { args, ok := ctx.Value(authKey).(*authorization) if !ok { return nil, errors.Errorf("Could not assert array type for %s", ctx.Value(authKey)) } symbols := make([]policy.Policy, len(args.policies)) for i, arg := range args.policies { symbols[i], ok = arg.(*policy.DefaultPolicy) if !ok { return nil, errors.Errorf("Could not assert policy type for %s", ctx.Value(authKey)) } } return symbols, nil }
func IsAuthenticatedFromContext(ctx context.Context) bool { a, b := ctx.Value(authKey).(*authorization) return (b && a.token != nil && a.token.Valid) }