Fix backchannel logout

Use access token to lookup session id. The userinfo endpoint does
not return the session id. Also add some debug logging.

Co-authored-by: Christian Richter <crichter@owncloud.com>
Co-authored-by: Michael Barz <mbarz@owncloud.com>
This commit is contained in:
Ralf Haferkamp
2023-04-20 18:04:52 +02:00
co-authored by Christian Richter Michael Barz
parent a08438c54e
commit 70a80125c3
4 changed files with 32 additions and 14 deletions
+12 -7
View File
@@ -27,7 +27,7 @@ import (
// OIDCClient used to mock the oidc client during tests
type OIDCClient interface {
UserInfo(ctx context.Context, ts oauth2.TokenSource) (*UserInfo, error)
VerifyAccessToken(ctx context.Context, token string) (jwt.RegisteredClaims, []string, error)
VerifyAccessToken(ctx context.Context, token string) (RegClaimsWithSID, []string, error)
VerifyLogoutToken(ctx context.Context, token string) (*LogoutToken, error)
}
@@ -46,6 +46,11 @@ type KeySet interface {
VerifySignature(ctx context.Context, jwt string) (payload []byte, err error)
}
type RegClaimsWithSID struct {
SessionID string `json:"sid"`
jwt.RegisteredClaims
}
type oidcClient struct {
// Logger to use for logging, must be set
Logger log.Logger
@@ -270,26 +275,26 @@ func (c *oidcClient) UserInfo(ctx context.Context, tokenSource oauth2.TokenSourc
}, nil
}
func (c *oidcClient) VerifyAccessToken(ctx context.Context, token string) (jwt.RegisteredClaims, []string, error) {
func (c *oidcClient) VerifyAccessToken(ctx context.Context, token string) (RegClaimsWithSID, []string, error) {
var mapClaims []string
if err := c.lookupWellKnownOpenidConfiguration(ctx); err != nil {
return jwt.RegisteredClaims{}, mapClaims, err
return RegClaimsWithSID{}, mapClaims, err
}
switch c.accessTokenVerifyMethod {
case config.AccessTokenVerificationJWT:
return c.verifyAccessTokenJWT(token)
case config.AccessTokenVerificationNone:
c.Logger.Debug().Msg("Access Token verification disabled")
return jwt.RegisteredClaims{}, mapClaims, nil
return RegClaimsWithSID{}, mapClaims, nil
default:
c.Logger.Error().Str("access_token_verify_method", c.accessTokenVerifyMethod).Msg("Unknown Access Token verification setting")
return jwt.RegisteredClaims{}, mapClaims, errors.New("unknown Access Token Verification method")
return RegClaimsWithSID{}, mapClaims, errors.New("unknown Access Token Verification method")
}
}
// verifyAccessTokenJWT tries to parse and verify the access token as a JWT.
func (c *oidcClient) verifyAccessTokenJWT(token string) (jwt.RegisteredClaims, []string, error) {
var claims jwt.RegisteredClaims
func (c *oidcClient) verifyAccessTokenJWT(token string) (RegClaimsWithSID, []string, error) {
var claims RegClaimsWithSID
var mapClaims []string
jwks := c.getKeyfunc()
if jwks == nil {