From a392cc109880758c97fd899ad453b4ff7ea91026 Mon Sep 17 00:00:00 2001 From: Adrian Aneci Date: Mon, 7 Mar 2022 18:54:24 +0200 Subject: [PATCH] Add groups to session too when creating session from token --- CHANGELOG.md | 1 + pkg/apis/middleware/session.go | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 452d644..f4c3e3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ## Changes since v7.2.1 +- [#1583](https://github.com/oauth2-proxy/oauth2-proxy/pull/1583) Add groups to session too when creating session from bearer token (@adriananeci) - [#1418](https://github.com/oauth2-proxy/oauth2-proxy/pull/1418) Support for passing arbitrary query parameters through from `/oauth2/start` to the identity provider's login URL. Configuration settings control which parameters are passed by default and precisely which values can be overridden per-request (@ianroberts) - [#1559](https://github.com/oauth2-proxy/oauth2-proxy/pull/1559) Introduce ProviderVerifier to clean up OIDC discovery code (@JoelSpeed) - [#1561](https://github.com/oauth2-proxy/oauth2-proxy/pull/1561) Add ppc64le support (@mgiessing) diff --git a/pkg/apis/middleware/session.go b/pkg/apis/middleware/session.go index f95467b..9fcd974 100644 --- a/pkg/apis/middleware/session.go +++ b/pkg/apis/middleware/session.go @@ -20,10 +20,11 @@ type VerifyFunc func(ctx context.Context, token string) (*oidc.IDToken, error) func CreateTokenToSessionFunc(verify VerifyFunc) TokenToSessionFunc { return func(ctx context.Context, token string) (*sessionsapi.SessionState, error) { var claims struct { - Subject string `json:"sub"` - Email string `json:"email"` - Verified *bool `json:"email_verified"` - PreferredUsername string `json:"preferred_username"` + Subject string `json:"sub"` + Email string `json:"email"` + Verified *bool `json:"email_verified"` + PreferredUsername string `json:"preferred_username"` + Groups []string `json:"groups"` } idToken, err := verify(ctx, token) @@ -46,6 +47,7 @@ func CreateTokenToSessionFunc(verify VerifyFunc) TokenToSessionFunc { newSession := &sessionsapi.SessionState{ Email: claims.Email, User: claims.Subject, + Groups: claims.Groups, PreferredUsername: claims.PreferredUsername, AccessToken: token, IDToken: token,