Corresponds to get_username_from_domain feature in sso-provider.
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>
# in the directory where your API server is running.
AnonymousUserToken: ""
+ # If a new user has an alternate email address (local@domain)
+ # with the domain given here, its local part becomes the new
+ # user's default username. Otherwise, the user's primary email
+ # address is used.
+ PreferDomainForUsername: ""
+
AuditLogs:
# Time to keep audit logs, in seconds. (An audit log is a row added
# to the "logs" table in the PostgreSQL database each time an
"Users.NewInactiveUserNotificationRecipients": false,
"Users.NewUserNotificationRecipients": false,
"Users.NewUsersAreActive": false,
+ "Users.PreferDomainForUsername": false,
"Users.UserNotifierEmailFrom": false,
"Users.UserProfileNotificationAddress": false,
"Volumes": true,
# in the directory where your API server is running.
AnonymousUserToken: ""
+ # If a new user has an alternate email address (local@domain)
+ # with the domain given here, its local part becomes the new
+ # user's default username. Otherwise, the user's primary email
+ # address is used.
+ PreferDomainForUsername: ""
+
AuditLogs:
# Time to keep audit logs, in seconds. (An audit log is a row added
# to the "logs" table in the PostgreSQL database each time an
for ae := range altEmails {
if ae != ret.Email {
ret.AlternateEmails = append(ret.AlternateEmails, ae)
+ if i := strings.Index(ae, "@"); i > 0 && strings.ToLower(ae[i+1:]) == strings.ToLower(cluster.Users.PreferDomainForUsername) {
+ ret.Username = strings.SplitN(ae[:i], "+", 2)[0]
+ }
}
}
return &ret, nil
s.cluster, err = cfg.GetCluster("")
s.cluster.Login.GoogleClientID = "test%client$id"
s.cluster.Login.GoogleClientSecret = "test#client/secret"
+ s.cluster.Users.PreferDomainForUsername = "PreferDomainForUsername.example.com"
c.Assert(err, check.IsNil)
s.localdb = NewConn(s.cluster)
"metadata": map[string]interface{}{"verified": true},
"value": "joe.smith@alternate.example.com",
},
+ {
+ "metadata": map[string]interface{}{"verified": true},
+ "value": "joe.smith@preferdomainforusername.example.com",
+ },
},
}
state := s.startLogin(c)
})
authinfo := s.getCallbackAuthInfo(c)
c.Check(authinfo.Email, check.Equals, "joe.smith@primary.example.com")
- c.Check(authinfo.AlternateEmails, check.DeepEquals, []string{"joe.smith@alternate.example.com"})
+ c.Check(authinfo.AlternateEmails, check.DeepEquals, []string{"joe.smith@alternate.example.com", "joe.smith@preferdomainforusername.example.com"})
+ c.Check(authinfo.Username, check.Equals, "joe.smith")
}
func (s *LoginSuite) TestGoogleLogin_NoPrimaryEmailAddress(c *check.C) {
authinfo := s.getCallbackAuthInfo(c)
c.Check(authinfo.Email, check.Equals, "joe.smith@work.example.com") // first verified email in People response
c.Check(authinfo.AlternateEmails, check.DeepEquals, []string{"joe.smith@home.example.com"})
+ c.Check(authinfo.Username, check.Equals, "")
}
func (s *LoginSuite) getCallbackAuthInfo(c *check.C) (authinfo rpc.UserSessionAuthInfo) {
AlternateEmails []string `json:"alternate_emails"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
+ Username string `json:"username"`
}
type UserSessionCreateOptions struct {
NewUsersAreActive bool
UserNotifierEmailFrom string
UserProfileNotificationAddress string
+ PreferDomainForUsername string
}
Volumes map[string]Volume
Workbench struct {
:is_admin => false,
:is_active => Rails.configuration.Users.NewUsersAreActive)
- primary_user.set_initial_username(requested: info['username']) if info['username']
+ primary_user.set_initial_username(requested: info['username']) if info['username'] && !info['username'].blank?
primary_user.identity_url = info['identity_url'] if identity_url
end