Files
opencloud/oidc/context.go
Jörn Friedrich Dreyer d9e0380d80 introduce oidc middleware
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
2019-12-11 15:32:22 +01:00

18 lines
527 B
Go

package oidc
import "context"
// contextKey is the key for oidc claims in a context
type contextKey struct{}
// NewContext makes a new context that contains the OpenID Connect claims.
func NewContext(parent context.Context, c *StandardClaims) context.Context {
return context.WithValue(parent, contextKey{}, c)
}
// FromContext returns the StandardClaims stored in a context, or nil if there isn't one.
func FromContext(ctx context.Context) *StandardClaims {
s, _ := ctx.Value(contextKey{}).(*StandardClaims)
return s
}