1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-01-06 03:53:54 +02:00

Fix default scope settings for none oidc providers like GitHub (#1927)

* fix default scope settings for none oidc providers

* add changelog for bugfix

* fix scope test cases by producing and accessing correct result value
This commit is contained in:
Jan Larwig 2022-12-23 10:00:57 +01:00 committed by GitHub
parent ddcc433a97
commit 8b77c97009
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 7 deletions

View File

@ -12,6 +12,7 @@
- [#1882](https://github.com/oauth2-proxy/oauth2-proxy/pull/1882) Make `htpasswd.GetUsers` racecondition safe
- [#1883](https://github.com/oauth2-proxy/oauth2-proxy/pull/1883) Ensure v8 manifest variant is set on docker images
- [#1906](https://github.com/oauth2-proxy/oauth2-proxy/pull/1906) Fix PKCE code verifier generation to never use UTF-8 characters
- [#1927](https://github.com/oauth2-proxy/oauth2-proxy/pull/1927) Fix default scope settings for none oidc providers
# V7.4.0

View File

@ -152,7 +152,7 @@ func newProviderDataFromConfig(providerConfig options.Provider) (*ProviderData,
p.EmailClaim = providerConfig.OIDCConfig.UserIDClaim
}
if p.Scope == "" {
if providerConfig.Type == "oidc" && p.Scope == "" {
p.Scope = "openid email profile"
if len(providerConfig.AllowedGroups) > 0 {

View File

@ -125,32 +125,48 @@ func TestScope(t *testing.T) {
testCases := []struct {
name string
configuredType options.ProviderType
configuredScope string
expectedScope string
allowedGroups []string
}{
{
name: "with no scope provided",
name: "oidc: with no scope provided",
configuredType: "oidc",
configuredScope: "",
expectedScope: "openid email profile",
},
{
name: "with no scope provided and groups",
name: "oidc: with no scope provided and groups",
configuredType: "oidc",
configuredScope: "",
expectedScope: "openid email profile groups",
allowedGroups: []string{"foo"},
},
{
name: "with a configured scope provided",
name: "oidc: with a configured scope provided",
configuredType: "oidc",
configuredScope: "openid",
expectedScope: "openid",
},
{
name: "github: with no scope provided",
configuredType: "github",
configuredScope: "",
expectedScope: "user:email",
},
{
name: "github: with a configured scope provided",
configuredType: "github",
configuredScope: "user:email org:read",
expectedScope: "user:email org:read",
},
}
for _, tc := range testCases {
providerConfig := options.Provider{
ID: providerID,
Type: "oidc",
Type: tc.configuredType,
ClientID: clientID,
ClientSecretFile: clientSecret,
LoginURL: msAuthURL,
@ -164,10 +180,10 @@ func TestScope(t *testing.T) {
},
}
pd, err := newProviderDataFromConfig(providerConfig)
pd, err := NewProvider(providerConfig)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(pd.Scope).To(Equal(tc.expectedScope))
g.Expect(pd.Data().Scope).To(Equal(tc.expectedScope))
}
}