mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:07:31 +00:00
fix: ensure minimal scope for azure ad (#5686)
* fix: ensure minimal scope for azure ad * docs(idps): mention scopes which are always sent --------- Co-authored-by: adlerhurst <silvan.reusser@gmail.com>
This commit is contained in:
@@ -77,7 +77,7 @@ You only have to add the client ID and secret, you have created in the step befo
|
|||||||
You can configure the following settings if you like, a useful default will be filled if you don't change anything:
|
You can configure the following settings if you like, a useful default will be filled if you don't change anything:
|
||||||
|
|
||||||
**Scopes**: The scopes define which scopes will be sent to the provider, `openid`, `profile`, and `email` are prefilled.
|
**Scopes**: The scopes define which scopes will be sent to the provider, `openid`, `profile`, and `email` are prefilled.
|
||||||
This information will be taken to create/update the user within ZITADEL. Make sure to also add `User.Read`
|
This information will be taken to create/update the user within ZITADEL. Make sure to also add `User.Read`. ZITADEL ensures that at least `openid` and `User.Read` scopes are always sent.
|
||||||
|
|
||||||
**Email Verified**: Azure AD doesn't send the email verified claim in the users token, if you don't enable this setting.
|
**Email Verified**: Azure AD doesn't send the email verified claim in the users token, if you don't enable this setting.
|
||||||
The user is then created with an unverified email, which results in an email verification message.
|
The user is then created with an unverified email, which results in an email verification message.
|
||||||
|
@@ -61,7 +61,7 @@ The GitHub provider templates have everything you need preconfigured. You only h
|
|||||||
You can configure the following settings if you like, a useful default will be filled if you don't change anything:
|
You can configure the following settings if you like, a useful default will be filled if you don't change anything:
|
||||||
|
|
||||||
**Scopes**: The scopes define which scopes will be sent to the provider, `openid`, `profile`, and `email` are prefilled.
|
**Scopes**: The scopes define which scopes will be sent to the provider, `openid`, `profile`, and `email` are prefilled.
|
||||||
This information is used to create and/or update the user within ZITADEL.
|
This information is used to create and/or update the user within ZITADEL. ZITADEL ensures that at least the `openid`-scope is always sent.
|
||||||
|
|
||||||
<GeneralConfigDescription provider_account="GitHub account" />
|
<GeneralConfigDescription provider_account="GitHub account" />
|
||||||
|
|
||||||
|
@@ -62,7 +62,7 @@ Add the client ID and secret you have created in the Gitlab Application.
|
|||||||
|
|
||||||
You can configure the following settings if you like, a useful default will be filled if you don't change anything:
|
You can configure the following settings if you like, a useful default will be filled if you don't change anything:
|
||||||
|
|
||||||
**Scopes**: The scopes define which scopes will be sent to the provider, `openid`, `profile`, and `email` are prefilled. This informations will be taken to create/update the user within ZITADEL.
|
**Scopes**: The scopes define which scopes will be sent to the provider, `openid`, `profile`, and `email` are prefilled. This informations will be taken to create/update the user within ZITADEL. ZITADEL ensures that at least the `openid`-scope is always sent.
|
||||||
|
|
||||||
<GeneralConfigDescription provider_account="GitLab account" />
|
<GeneralConfigDescription provider_account="GitLab account" />
|
||||||
|
|
||||||
|
@@ -45,7 +45,7 @@ Add the client ID and secret created before on your Google App.
|
|||||||
|
|
||||||
You can configure the following settings if you like, a useful default will be filled if you don't change anything:
|
You can configure the following settings if you like, a useful default will be filled if you don't change anything:
|
||||||
|
|
||||||
**Scopes**: The scopes define which scopes will be sent to the provider, `openid`, `profile`, and `email` are prefilled. This information will be taken to create/update the user within ZITADEL.
|
**Scopes**: The scopes define which scopes will be sent to the provider, `openid`, `profile`, and `email` are prefilled. This information will be taken to create/update the user within ZITADEL. ZITADEL ensures that at least the `openid`-scope is always sent.
|
||||||
|
|
||||||
|
|
||||||
<GeneralConfigDescription provider_account="Google account" />
|
<GeneralConfigDescription provider_account="Google account" />
|
||||||
|
@@ -16,6 +16,8 @@ const (
|
|||||||
authURLTemplate string = "https://login.microsoftonline.com/%s/oauth2/v2.0/authorize"
|
authURLTemplate string = "https://login.microsoftonline.com/%s/oauth2/v2.0/authorize"
|
||||||
tokenURLTemplate string = "https://login.microsoftonline.com/%s/oauth2/v2.0/token"
|
tokenURLTemplate string = "https://login.microsoftonline.com/%s/oauth2/v2.0/token"
|
||||||
userinfoURL string = "https://graph.microsoft.com/v1.0/me"
|
userinfoURL string = "https://graph.microsoft.com/v1.0/me"
|
||||||
|
|
||||||
|
ScopeUserRead string = "User.Read"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TenantType are the well known tenant types to scope the users that can authenticate. TenantType is not an
|
// TenantType are the well known tenant types to scope the users that can authenticate. TenantType is not an
|
||||||
@@ -99,7 +101,7 @@ func New(name, clientID, clientSecret, redirectURI string, scopes []string, opts
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newConfig(tenant TenantType, clientID, secret, callbackURL string, scopes []string) *oauth2.Config {
|
func newConfig(tenant TenantType, clientID, secret, callbackURL string, scopes []string) *oauth2.Config {
|
||||||
c := &oauth2.Config{
|
return &oauth2.Config{
|
||||||
ClientID: clientID,
|
ClientID: clientID,
|
||||||
ClientSecret: secret,
|
ClientSecret: secret,
|
||||||
RedirectURL: callbackURL,
|
RedirectURL: callbackURL,
|
||||||
@@ -107,13 +109,34 @@ func newConfig(tenant TenantType, clientID, secret, callbackURL string, scopes [
|
|||||||
AuthURL: fmt.Sprintf(authURLTemplate, tenant),
|
AuthURL: fmt.Sprintf(authURLTemplate, tenant),
|
||||||
TokenURL: fmt.Sprintf(tokenURLTemplate, tenant),
|
TokenURL: fmt.Sprintf(tokenURLTemplate, tenant),
|
||||||
},
|
},
|
||||||
Scopes: []string{oidc.ScopeOpenID},
|
Scopes: ensureMinimalScope(scopes),
|
||||||
}
|
|
||||||
if len(scopes) > 0 {
|
|
||||||
c.Scopes = scopes
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return c
|
// ensureMinimalScope ensures that at least openid and `User.Read` ist set
|
||||||
|
// if none is provided it will request `openid profile email phone User.Read`
|
||||||
|
func ensureMinimalScope(scopes []string) []string {
|
||||||
|
if len(scopes) == 0 {
|
||||||
|
return []string{oidc.ScopeOpenID, oidc.ScopeProfile, oidc.ScopeEmail, oidc.ScopePhone, ScopeUserRead}
|
||||||
|
}
|
||||||
|
var openIDSet, userReadSet bool
|
||||||
|
for _, scope := range scopes {
|
||||||
|
if scope == oidc.ScopeOpenID {
|
||||||
|
openIDSet = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if scope == ScopeUserRead {
|
||||||
|
userReadSet = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !openIDSet {
|
||||||
|
scopes = append(scopes, oidc.ScopeOpenID)
|
||||||
|
}
|
||||||
|
if !userReadSet {
|
||||||
|
scopes = append(scopes, ScopeUserRead)
|
||||||
|
}
|
||||||
|
return scopes
|
||||||
}
|
}
|
||||||
|
|
||||||
// User represents the structure return on the userinfo endpoint and implements the [idp.User] interface
|
// User represents the structure return on the userinfo endpoint and implements the [idp.User] interface
|
||||||
|
@@ -36,7 +36,7 @@ func TestProvider_BeginAuth(t *testing.T) {
|
|||||||
redirectURI: "redirectURI",
|
redirectURI: "redirectURI",
|
||||||
},
|
},
|
||||||
want: &oidc.Session{
|
want: &oidc.Session{
|
||||||
AuthURL: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=clientID&prompt=select_account&redirect_uri=redirectURI&response_type=code&scope=openid&state=testState",
|
AuthURL: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=clientID&prompt=select_account&redirect_uri=redirectURI&response_type=code&scope=openid+profile+email+phone+User.Read&state=testState",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -50,7 +50,7 @@ func TestProvider_BeginAuth(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: &oidc.Session{
|
want: &oidc.Session{
|
||||||
AuthURL: "https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize?client_id=clientID&prompt=select_account&redirect_uri=redirectURI&response_type=code&scope=openid&state=testState",
|
AuthURL: "https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize?client_id=clientID&prompt=select_account&redirect_uri=redirectURI&response_type=code&scope=openid+profile+email+phone+User.Read&state=testState",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -59,13 +59,13 @@ func TestProvider_BeginAuth(t *testing.T) {
|
|||||||
clientID: "clientID",
|
clientID: "clientID",
|
||||||
clientSecret: "clientSecret",
|
clientSecret: "clientSecret",
|
||||||
redirectURI: "redirectURI",
|
redirectURI: "redirectURI",
|
||||||
scopes: []string{openid.ScopeOpenID, openid.ScopeProfile, "user"},
|
scopes: []string{openid.ScopeOpenID, openid.ScopeProfile, "custom"},
|
||||||
options: []ProviderOptions{
|
options: []ProviderOptions{
|
||||||
WithTenant(ConsumersTenant),
|
WithTenant(ConsumersTenant),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: &oidc.Session{
|
want: &oidc.Session{
|
||||||
AuthURL: "https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize?client_id=clientID&prompt=select_account&redirect_uri=redirectURI&response_type=code&scope=openid+profile+user&state=testState",
|
AuthURL: "https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize?client_id=clientID&prompt=select_account&redirect_uri=redirectURI&response_type=code&scope=openid+profile+custom+User.Read&state=testState",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user