proxy(oidc): Emit a UserSignedIn event on new session
Every time the OIDC middleware sees a new access token (i.e when it needs to update the userinfo cache) we consider that as a new login. In this case the middleware add a new flag to the context, which is then used by the accountresolver middleware to publish a UserSignedIn event. The event needs to be sent by the accountresolver middleware, because only at that point we know the user id of the user that just logged in. (It would probably makes sense to merge the auth and account middleware into a single component to avoid passing flags around via context)
This commit is contained in:
committed by
Ralf Haferkamp
parent
3b0ff50bf0
commit
cb8934081f
@@ -5,6 +5,9 @@ import "context"
|
||||
// contextKey is the key for oidc claims in a context
|
||||
type contextKey struct{}
|
||||
|
||||
// newSessionFlagKey is the key for the new session flag in a context
|
||||
type newSessionFlagKey struct{}
|
||||
|
||||
// NewContext makes a new context that contains the OpenID connect claims in a map.
|
||||
func NewContext(parent context.Context, c map[string]interface{}) context.Context {
|
||||
return context.WithValue(parent, contextKey{}, c)
|
||||
@@ -15,3 +18,14 @@ func FromContext(ctx context.Context) map[string]interface{} {
|
||||
s, _ := ctx.Value(contextKey{}).(map[string]interface{})
|
||||
return s
|
||||
}
|
||||
|
||||
// NewContextSessionFlag makes a new context that contains the new session flag.
|
||||
func NewContextSessionFlag(ctx context.Context, flag bool) context.Context {
|
||||
return context.WithValue(ctx, newSessionFlagKey{}, flag)
|
||||
}
|
||||
|
||||
// NewSessionFlagFromContext returns the new session flag stored in a context.
|
||||
func NewSessionFlagFromContext(ctx context.Context) bool {
|
||||
s, _ := ctx.Value(newSessionFlagKey{}).(bool)
|
||||
return s
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user