Skip to content

Commit

Permalink
add config to explicitly set scopes for microsoft connector (dexidp#2582
Browse files Browse the repository at this point in the history
)

Signed-off-by: Bob Callaway <bcallaway@google.com>
  • Loading branch information
bobcallaway authored Jul 27, 2022
1 parent 83e2df8 commit e1a4078
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion connector/microsoft/microsoft.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type Config struct {
// For valid values, see https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow#request-an-authorization-code.
PromptType string `json:"promptType"`
DomainHint string `json:"domainHint"`

Scopes []string `json:"scopes"` // defaults to scopeUser (user.read)
}

// Open returns a strategy for logging in through Microsoft.
Expand All @@ -77,6 +79,7 @@ func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error)
emailToLowercase: c.EmailToLowercase,
promptType: c.PromptType,
domainHint: c.DomainHint,
scopes: c.Scopes,
}
// By default allow logins from both personal and business/school
// accounts.
Expand Down Expand Up @@ -122,6 +125,7 @@ type microsoftConnector struct {
emailToLowercase bool
promptType string
domainHint string
scopes []string
}

func (c *microsoftConnector) isOrgTenant() bool {
Expand All @@ -133,7 +137,12 @@ func (c *microsoftConnector) groupsRequired(groupScope bool) bool {
}

func (c *microsoftConnector) oauth2Config(scopes connector.Scopes) *oauth2.Config {
microsoftScopes := []string{scopeUser}
var microsoftScopes []string
if len(c.scopes) > 0 {
microsoftScopes = c.scopes
} else {
microsoftScopes = append(microsoftScopes, scopeUser)
}
if c.groupsRequired(scopes.Groups) {
microsoftScopes = append(microsoftScopes, scopeGroups)
}
Expand Down

0 comments on commit e1a4078

Please sign in to comment.