Added the possibility to acticate lowercase for UPN-Strings

Signed-off-by: Maik Brauer <maik.brauer@vodafone.com>
This commit is contained in:
Maik Brauer 2020-12-18 15:08:53 +01:00
parent 31839549cd
commit eb9ef3b0ec
2 changed files with 10 additions and 0 deletions

View file

@ -9,6 +9,7 @@ import (
"fmt"
"io"
"net/http"
"strings"
"sync"
"time"
@ -51,6 +52,7 @@ type Config struct {
Groups []string `json:"groups"`
GroupNameFormat GroupNameFormat `json:"groupNameFormat"`
UseGroupsAsWhitelist bool `json:"useGroupsAsWhitelist"`
UpnToLowercase bool `json:"upnToLowercase"`
}
// Open returns a strategy for logging in through Microsoft.
@ -67,6 +69,7 @@ func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error)
groupNameFormat: c.GroupNameFormat,
useGroupsAsWhitelist: c.UseGroupsAsWhitelist,
logger: logger,
upnToLowercase: c.UpnToLowercase,
}
// By default allow logins from both personal and business/school
// accounts.
@ -109,6 +112,7 @@ type microsoftConnector struct {
groups []string
useGroupsAsWhitelist bool
logger log.Logger
upnToLowercase bool
}
func (c *microsoftConnector) isOrgTenant() bool {
@ -171,6 +175,10 @@ func (c *microsoftConnector) HandleCallback(s connector.Scopes, r *http.Request)
return identity, fmt.Errorf("microsoft: get user: %v", err)
}
if c.upnToLowercase {
user.Email = strings.ToLower(user.Email)
}
identity = connector.Identity{
UserID: user.ID,
Username: user.Name,

2
go.mod
View file

@ -25,6 +25,7 @@ require (
github.com/lib/pq v1.3.0
github.com/mattermost/xml-roundtrip-validator v0.0.0-20201204154048-1a8688af4cf1
github.com/mattn/go-sqlite3 v1.11.0
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/pkg/errors v0.9.1
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
github.com/prometheus/client_golang v1.4.0
@ -46,6 +47,7 @@ require (
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect
gopkg.in/ldap.v2 v2.5.1
gopkg.in/square/go-jose.v2 v2.4.1
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc // indirect
sigs.k8s.io/testing_frameworks v0.1.2
)