mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-07 04:40:05 -06:00
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)
32 lines
1.0 KiB
Go
32 lines
1.0 KiB
Go
package oidc
|
|
|
|
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)
|
|
}
|
|
|
|
// FromContext returns the claims map stored in a context, or nil if there isn't one.
|
|
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
|
|
}
|