Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the possibility to activate lowercase for UPN-Strings #1888

Merged
merged 4 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions connector/microsoft/microsoft.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"io"
"net/http"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -51,6 +52,7 @@ type Config struct {
Groups []string `json:"groups"`
GroupNameFormat GroupNameFormat `json:"groupNameFormat"`
UseGroupsAsWhitelist bool `json:"useGroupsAsWhitelist"`
UpnToLowercase bool `json:"upnToLowercase"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not intimately familiar with microsoft/AD, but I think it would make sense to use email as a phrase here. I guess the UPN is always an email address.

}

// Open returns a strategy for logging in through Microsoft.
Expand All @@ -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.
Expand Down Expand Up @@ -109,6 +112,7 @@ type microsoftConnector struct {
groups []string
useGroupsAsWhitelist bool
logger log.Logger
upnToLowercase bool
}

func (c *microsoftConnector) isOrgTenant() bool {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this added as a dependency?

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
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this added as a dependency?

sigs.k8s.io/testing_frameworks v0.1.2
)

Expand Down