Improved claims handling

This commit is contained in:
Stefan Kürzeder 2020-06-04 15:29:18 +02:00
parent f7c659dbf1
commit 140cbf807d
2 changed files with 3 additions and 11 deletions
pkg/forwardauth

View file

@ -6,7 +6,6 @@ package forwardauth
import (
"context"
"encoding/json"
"errors"
"net/http"
"strings"
@ -18,7 +17,7 @@ import (
type AuthenticatationResult struct {
IDToken string
RefreshToken string
IDTokenClaims *json.RawMessage
IDTokenClaims *Claims
}
func (fw *ForwardAuth) HandleAuthentication(ctx context.Context, logger *logrus.Entry, state string, code string) (*AuthenticatationResult, error) {
@ -88,13 +87,7 @@ func (fw *ForwardAuth) IsAuthenticated(context context.Context, logger *logrus.E
http.SetCookie(w, fw.MakeRefreshAuthCookie(options, result))
}
err = json.Unmarshal(*result.IDTokenClaims, &claims)
if err != nil {
logger.Error(err.Error())
return &claims, err
}
return &claims, nil
return result.IDTokenClaims, nil
case err != nil: // Other error
logger.Error(err.Error())

View file

@ -6,7 +6,6 @@ package forwardauth
import (
"context"
"encoding/json"
"errors"
"golang.org/x/oauth2"
@ -25,7 +24,7 @@ func (fw *ForwardAuth) VerifyToken(ctx context.Context, oauth2Token *oauth2.Toke
return result, err
}
result = AuthenticatationResult{rawIDToken, oauth2Token.RefreshToken, new(json.RawMessage)}
result = AuthenticatationResult{rawIDToken, oauth2Token.RefreshToken, new(Claims)}
if err := idToken.Claims(&result.IDTokenClaims); err != nil {
return result, err
}