-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Split identity and user objects #1450
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,15 +24,22 @@ import ( | |
| // A successful response may also include name and/or email: | ||
| // {"id":"userid", "name": "User Name", "email":"[email protected]"} | ||
| type Authenticator struct { | ||
| url string | ||
| mapper authapi.UserIdentityMapper | ||
| providerName string | ||
| url string | ||
| mapper authapi.UserIdentityMapper | ||
| } | ||
|
|
||
| // RemoteUserData holds user data returned from a remote basic-auth protected endpoint. | ||
| // These field names can not be changed unless external integrators are also updated. | ||
| type RemoteUserData struct { | ||
| ID string | ||
| Name string | ||
| // ID is the immutable identity of the user | ||
| ID string | ||
| // Login is the optional login of the user | ||
| // Useful when the id is different than the username/login used by the user to authenticate | ||
| Login string | ||
| // Name is the optional display name of the user | ||
| Name string | ||
| // Email is the optional email address of the user | ||
| Email string | ||
| } | ||
|
|
||
|
|
@@ -42,8 +49,8 @@ type RemoteError struct { | |
| } | ||
|
|
||
| // New returns an authenticator which will make a basic auth call to the given url. | ||
| func New(url string, mapper authapi.UserIdentityMapper) authenticator.Password { | ||
| return &Authenticator{url, mapper} | ||
| func New(providerName string, url string, mapper authapi.UserIdentityMapper) authenticator.Password { | ||
| return &Authenticator{providerName, url, mapper} | ||
| } | ||
|
|
||
| func (a *Authenticator) AuthenticatePassword(username, password string) (user.Info, bool, error) { | ||
|
|
@@ -89,13 +96,10 @@ func (a *Authenticator) AuthenticatePassword(username, password string) (user.In | |
| return nil, false, errors.New("Could not retrieve user data") | ||
| } | ||
|
|
||
| identity := &authapi.DefaultUserIdentityInfo{ | ||
| UserName: username, | ||
| Extra: map[string]string{ | ||
| "name": remoteUserData.Name, | ||
| "email": remoteUserData.Email, | ||
| }, | ||
| } | ||
| identity := authapi.NewDefaultUserIdentityInfo(a.providerName, remoteUserData.ID) | ||
| identity.Extra[authapi.IdentityDisplayNameKey] = remoteUserData.Name | ||
| identity.Extra[authapi.IdentityLoginKey] = remoteUserData.Login | ||
| identity.Extra[authapi.IdentityEmailKey] = remoteUserData.Email | ||
| user, err := a.mapper.UserFor(identity) | ||
| glog.V(4).Infof("Got userIdentityMapping: %#v", user) | ||
| if err != nil { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,12 +22,13 @@ func NewDefaultConfig() *Config { | |
| } | ||
|
|
||
| type Authenticator struct { | ||
| config *Config | ||
| mapper authapi.UserIdentityMapper | ||
| providerName string | ||
| config *Config | ||
| mapper authapi.UserIdentityMapper | ||
| } | ||
|
|
||
| func NewAuthenticator(config *Config, mapper authapi.UserIdentityMapper) *Authenticator { | ||
| return &Authenticator{config, mapper} | ||
| func NewAuthenticator(providerName string, config *Config, mapper authapi.UserIdentityMapper) *Authenticator { | ||
| return &Authenticator{providerName, config, mapper} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. providerName must not be empty. That's a global thing.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather catch that in config validation (future) and/or identity validation (which happens now) |
||
| } | ||
|
|
||
| func (a *Authenticator) AuthenticateRequest(req *http.Request) (user.Info, bool, error) { | ||
|
|
@@ -46,9 +47,7 @@ func (a *Authenticator) AuthenticateRequest(req *http.Request) (user.Info, bool, | |
| return nil, false, nil | ||
| } | ||
|
|
||
| identity := &authapi.DefaultUserIdentityInfo{ | ||
| UserName: username, | ||
| } | ||
| identity := authapi.NewDefaultUserIdentityInfo(a.providerName, username) | ||
| user, err := a.mapper.UserFor(identity) | ||
| if err != nil { | ||
| return nil, false, err | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't used how you'd expect.
GetProviderName()is never called. That suggests that this is the wrong abstractionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. Moved configurable providerName from the mapper into the various identity providers. I'm not sure why I didn't want to trust the identity providers to set the providerName on the identity info they give to the mapper