add RegexSelector
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
@@ -26,7 +26,7 @@ func AccountResolver(optionSetters ...Option) func(next http.Handler) http.Handl
|
||||
"expires": int64(60),
|
||||
})
|
||||
if err != nil {
|
||||
logger.Fatal().Err(err).Msgf("Could not initialize token-manager")
|
||||
logger.Fatal().Err(err).Msg("Could not initialize token-manager")
|
||||
}
|
||||
|
||||
return &accountResolver{
|
||||
@@ -53,8 +53,9 @@ type accountResolver struct {
|
||||
|
||||
// TODO do not use the context to store values: https://medium.com/@cep21/how-to-correctly-use-context-context-in-go-1-7-8f2c0fafdf39
|
||||
func (m accountResolver) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
claims := oidc.FromContext(req.Context())
|
||||
u, ok := revauser.ContextGetUser(req.Context())
|
||||
ctx := req.Context()
|
||||
claims := oidc.FromContext(ctx)
|
||||
u, ok := revauser.ContextGetUser(ctx)
|
||||
|
||||
if claims == nil && !ok {
|
||||
m.next.ServeHTTP(w, req)
|
||||
@@ -99,6 +100,10 @@ func (m accountResolver) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// add user to context for selectors
|
||||
ctx = revauser.ContextSetUser(ctx, u)
|
||||
req = req.WithContext(ctx)
|
||||
|
||||
m.logger.Debug().Interface("claims", claims).Interface("user", u).Msg("associated claims with user")
|
||||
}
|
||||
|
||||
@@ -107,7 +112,7 @@ func (m accountResolver) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
m.logger.Error().Err(err).Msg("could not get owner scope")
|
||||
return
|
||||
}
|
||||
token, err := m.tokenManager.MintToken(req.Context(), u, s)
|
||||
token, err := m.tokenManager.MintToken(ctx, u, s)
|
||||
if err != nil {
|
||||
m.logger.Error().Err(err).Msg("could not mint token")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
|
||||
Reference in New Issue
Block a user