From eb9ef3b0ec8039689f2d78bad65c7666265ef9cc Mon Sep 17 00:00:00 2001 From: Maik Brauer Date: Fri, 18 Dec 2020 15:08:53 +0100 Subject: [PATCH 1/3] Added the possibility to acticate lowercase for UPN-Strings Signed-off-by: Maik Brauer --- connector/microsoft/microsoft.go | 8 ++++++++ go.mod | 2 ++ 2 files changed, 10 insertions(+) diff --git a/connector/microsoft/microsoft.go b/connector/microsoft/microsoft.go index ff27182d6e..0d82327035 100644 --- a/connector/microsoft/microsoft.go +++ b/connector/microsoft/microsoft.go @@ -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, diff --git a/go.mod b/go.mod index 86a1e9c834..69457b3b77 100644 --- a/go.mod +++ b/go.mod @@ -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 ) From 4d246bc9dc8392b1dea0fd945d6401fa40a85c4f Mon Sep 17 00:00:00 2001 From: Maik Brauer Date: Tue, 5 Jan 2021 17:10:57 +0100 Subject: [PATCH 2/3] Adapted recommendation from Maintainer for PR #1888 Signed-off-by: Maik Brauer --- connector/microsoft/microsoft.go | 8 ++++---- go.mod | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/connector/microsoft/microsoft.go b/connector/microsoft/microsoft.go index 0d82327035..f88c5dabd2 100644 --- a/connector/microsoft/microsoft.go +++ b/connector/microsoft/microsoft.go @@ -52,7 +52,7 @@ type Config struct { Groups []string `json:"groups"` GroupNameFormat GroupNameFormat `json:"groupNameFormat"` UseGroupsAsWhitelist bool `json:"useGroupsAsWhitelist"` - UpnToLowercase bool `json:"upnToLowercase"` + emailToLowercase bool `json:"emailToLowercase"` } // Open returns a strategy for logging in through Microsoft. @@ -69,7 +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, + emailToLowercase: c.EmailToLowercase, } // By default allow logins from both personal and business/school // accounts. @@ -112,7 +112,7 @@ type microsoftConnector struct { groups []string useGroupsAsWhitelist bool logger log.Logger - upnToLowercase bool + emailToLowercase bool } func (c *microsoftConnector) isOrgTenant() bool { @@ -175,7 +175,7 @@ func (c *microsoftConnector) HandleCallback(s connector.Scopes, r *http.Request) return identity, fmt.Errorf("microsoft: get user: %v", err) } - if c.upnToLowercase { + if c.emailToLowercase { user.Email = strings.ToLower(user.Email) } diff --git a/go.mod b/go.mod index 69457b3b77..86a1e9c834 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,6 @@ 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 @@ -47,7 +46,6 @@ 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 ) From c55f17ea64115779159a6efd24c1d71f6f172890 Mon Sep 17 00:00:00 2001 From: Maik Brauer Date: Tue, 5 Jan 2021 17:10:57 +0100 Subject: [PATCH 3/3] Adapted recommendation from Maintainer for PR #1888 Signed-off-by: Maik Brauer --- connector/microsoft/microsoft.go | 8 ++++---- go.mod | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/connector/microsoft/microsoft.go b/connector/microsoft/microsoft.go index 0d82327035..f88c5dabd2 100644 --- a/connector/microsoft/microsoft.go +++ b/connector/microsoft/microsoft.go @@ -52,7 +52,7 @@ type Config struct { Groups []string `json:"groups"` GroupNameFormat GroupNameFormat `json:"groupNameFormat"` UseGroupsAsWhitelist bool `json:"useGroupsAsWhitelist"` - UpnToLowercase bool `json:"upnToLowercase"` + emailToLowercase bool `json:"emailToLowercase"` } // Open returns a strategy for logging in through Microsoft. @@ -69,7 +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, + emailToLowercase: c.EmailToLowercase, } // By default allow logins from both personal and business/school // accounts. @@ -112,7 +112,7 @@ type microsoftConnector struct { groups []string useGroupsAsWhitelist bool logger log.Logger - upnToLowercase bool + emailToLowercase bool } func (c *microsoftConnector) isOrgTenant() bool { @@ -175,7 +175,7 @@ func (c *microsoftConnector) HandleCallback(s connector.Scopes, r *http.Request) return identity, fmt.Errorf("microsoft: get user: %v", err) } - if c.upnToLowercase { + if c.emailToLowercase { user.Email = strings.ToLower(user.Email) } diff --git a/go.mod b/go.mod index 69457b3b77..86a1e9c834 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,6 @@ 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 @@ -47,7 +46,6 @@ 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 )