Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
dex
Commits
45858500
Unverified
Commit
45858500
authored
May 08, 2019
by
Maxime Desrosiers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
microsoft: option for group UUIDs instead of name and group whitelist
parent
20a858da
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
8 deletions
+45
-8
microsoft.md
Documentation/connectors/microsoft.md
+7
-0
microsoft.go
connector/microsoft/microsoft.go
+38
-8
No files found.
Documentation/connectors/microsoft.md
View file @
45858500
...
...
@@ -88,6 +88,9 @@ a member of. `onlySecurityGroups` configuration option restricts the list to
include only security groups. By default all groups (security, Office 365,
mailing lists) are included.
By default, dex resolve groups ids to groups names, to keep groups ids, you can
specify the configuration option
`groupNameFormat: id`
.
It is possible to require a user to be a member of a particular group in order
to be successfully authenticated in dex. For example, with the following
configuration file only the users who are members of at least one of the listed
...
...
@@ -110,3 +113,6 @@ connectors:
-
developers
-
devops
```
Also,
`useGroupsAsWhitelist`
configuration option, can restrict the groups
claims to include only the user's groups that are in the configured
`groups`
.
\ No newline at end of file
connector/microsoft/microsoft.go
View file @
45858500
...
...
@@ -19,12 +19,23 @@ import (
"github.com/dexidp/dex/pkg/log"
)
// GroupNameFormat represents the format of the group identifier
// we use type of string instead of int because it's easier to
// marshall/unmarshall
type
GroupNameFormat
string
// Possible values for GroupNameFormat
const
(
GroupID
GroupNameFormat
=
"id"
GroupName
GroupNameFormat
=
"name"
)
const
(
apiURL
=
"https://graph.microsoft.com"
// Microsoft requires this scope to access user's profile
scopeUser
=
"user.read"
// Microsoft requires this scope to list groups the user is a member of
// and resolve their
UUID
s to groups names.
// and resolve their
id
s to groups names.
scopeGroups
=
"directory.read.all"
)
...
...
@@ -36,6 +47,8 @@ type Config struct {
Tenant
string
`json:"tenant"`
OnlySecurityGroups
bool
`json:"onlySecurityGroups"`
Groups
[]
string
`json:"groups"`
GroupNameFormat
GroupNameFormat
`json:"groupNameFormat"`
UseGroupsAsWhitelist
bool
`json:"useGroupsAsWhitelist"`
}
// Open returns a strategy for logging in through Microsoft.
...
...
@@ -47,6 +60,8 @@ func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error)
tenant
:
c
.
Tenant
,
onlySecurityGroups
:
c
.
OnlySecurityGroups
,
groups
:
c
.
Groups
,
groupNameFormat
:
c
.
GroupNameFormat
,
useGroupsAsWhitelist
:
c
.
UseGroupsAsWhitelist
,
logger
:
logger
,
}
// By default allow logins from both personal and business/school
...
...
@@ -55,6 +70,15 @@ func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error)
m
.
tenant
=
"common"
}
// By default, use group names
switch
m
.
groupNameFormat
{
case
""
:
m
.
groupNameFormat
=
GroupName
case
GroupID
,
GroupName
:
default
:
return
nil
,
fmt
.
Errorf
(
"invalid groupNameFormat: %s"
,
m
.
groupNameFormat
)
}
return
&
m
,
nil
}
...
...
@@ -75,7 +99,9 @@ type microsoftConnector struct {
clientSecret
string
tenant
string
onlySecurityGroups
bool
groupNameFormat
GroupNameFormat
groups
[]
string
useGroupsAsWhitelist
bool
logger
log
.
Logger
}
...
...
@@ -300,24 +326,28 @@ type group struct {
Name
string
`json:"displayName"`
}
func
(
c
*
microsoftConnector
)
getGroups
(
ctx
context
.
Context
,
client
*
http
.
Client
,
userID
string
)
(
groups
[]
string
,
err
error
)
{
id
s
,
err
:=
c
.
getGroupIDs
(
ctx
,
client
)
func
(
c
*
microsoftConnector
)
getGroups
(
ctx
context
.
Context
,
client
*
http
.
Client
,
userID
string
)
(
[]
string
,
error
)
{
userGroup
s
,
err
:=
c
.
getGroupIDs
(
ctx
,
client
)
if
err
!=
nil
{
return
groups
,
err
return
nil
,
err
}
groups
,
err
=
c
.
getGroupNames
(
ctx
,
client
,
ids
)
if
c
.
groupNameFormat
==
GroupName
{
userGroups
,
err
=
c
.
getGroupNames
(
ctx
,
client
,
userGroups
)
if
err
!=
nil
{
return
return
nil
,
err
}
}
// ensure that the user is in at least one required group
filteredGroups
:=
groups_pkg
.
Filter
(
g
roups
,
c
.
groups
)
filteredGroups
:=
groups_pkg
.
Filter
(
userG
roups
,
c
.
groups
)
if
len
(
c
.
groups
)
>
0
&&
len
(
filteredGroups
)
==
0
{
return
nil
,
fmt
.
Errorf
(
"microsoft: user %v not in any of the required groups"
,
userID
)
}
else
if
c
.
useGroupsAsWhitelist
{
return
filteredGroups
,
nil
}
return
return
userGroups
,
nil
}
func
(
c
*
microsoftConnector
)
getGroupIDs
(
ctx
context
.
Context
,
client
*
http
.
Client
)
(
ids
[]
string
,
err
error
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment