export all User fields

This commit is contained in:
David Sharnoff 2022-08-19 17:26:39 -07:00
parent 1073af88c2
commit 68daa3ed74
2 changed files with 31 additions and 31 deletions

View file

@ -87,10 +87,10 @@ func (s *storage) CheckUsernamePassword(username, password, id string) error {
// a plain text password. For real world scenarios, be sure to have the password // a plain text password. For real world scenarios, be sure to have the password
// hashed and salted (e.g. using bcrypt) // hashed and salted (e.g. using bcrypt)
user := s.userStore.GetUserByUsername(username) user := s.userStore.GetUserByUsername(username)
if user != nil && user.password == password { if user != nil && user.Password == password {
// be sure to set user id into the auth request after the user was checked, // be sure to set user id into the auth request after the user was checked,
// so that you'll be able to get more information about the user after the login // so that you'll be able to get more information about the user after the login
request.UserID = user.id request.UserID = user.ID
// you will have to change some state on the request to guide the user through possible multiple steps of the login process // you will have to change some state on the request to guide the user through possible multiple steps of the login process
// in this example we'll simply check the username / password and set a boolean to true // in this example we'll simply check the username / password and set a boolean to true
@ -541,17 +541,17 @@ func (s *storage) setUserinfo(ctx context.Context, userInfo oidc.UserInfoSetter,
for _, scope := range scopes { for _, scope := range scopes {
switch scope { switch scope {
case oidc.ScopeOpenID: case oidc.ScopeOpenID:
userInfo.SetSubject(user.id) userInfo.SetSubject(user.ID)
case oidc.ScopeEmail: case oidc.ScopeEmail:
userInfo.SetEmail(user.email, user.emailVerified) userInfo.SetEmail(user.Email, user.EmailVerified)
case oidc.ScopeProfile: case oidc.ScopeProfile:
userInfo.SetPreferredUsername(user.username) userInfo.SetPreferredUsername(user.Username)
userInfo.SetName(user.firstname + " " + user.lastname) userInfo.SetName(user.FirstName + " " + user.LastName)
userInfo.SetFamilyName(user.lastname) userInfo.SetFamilyName(user.LastName)
userInfo.SetGivenName(user.firstname) userInfo.SetGivenName(user.FirstName)
userInfo.SetLocale(user.preferredLanguage) userInfo.SetLocale(user.PreferredLanguage)
case oidc.ScopePhone: case oidc.ScopePhone:
userInfo.SetPhone(user.phone, user.phoneVerified) userInfo.SetPhone(user.Phone, user.PhoneVerified)
case CustomScope: case CustomScope:
// you can also have a custom scope and assert public or custom claims based on that // you can also have a custom scope and assert public or custom claims based on that
userInfo.AppendClaims(CustomClaim, customClaim(clientID)) userInfo.AppendClaims(CustomClaim, customClaim(clientID))

View file

@ -7,16 +7,16 @@ import (
) )
type User struct { type User struct {
id string ID string
username string Username string
password string Password string
firstname string FirstName string
lastname string LastName string
email string Email string
emailVerified bool EmailVerified bool
phone string Phone string
phoneVerified bool PhoneVerified bool
preferredLanguage language.Tag PreferredLanguage language.Tag
} }
type Service struct { type Service struct {
@ -36,16 +36,16 @@ func NewUserStore() UserStore {
return userStore{ return userStore{
users: map[string]*User{ users: map[string]*User{
"id1": { "id1": {
id: "id1", ID: "id1",
username: "test-user", Username: "test-user",
password: "verysecure", Password: "verysecure",
firstname: "Test", FirstName: "Test",
lastname: "User", LastName: "User",
email: "test-user@zitadel.ch", Email: "test-user@zitadel.ch",
emailVerified: true, EmailVerified: true,
phone: "", Phone: "",
phoneVerified: false, PhoneVerified: false,
preferredLanguage: language.German, PreferredLanguage: language.German,
}, },
}, },
} }
@ -57,7 +57,7 @@ func (u userStore) GetUserByID(id string) *User {
func (u userStore) GetUserByUsername(username string) *User { func (u userStore) GetUserByUsername(username string) *User {
for _, user := range u.users { for _, user := range u.users {
if user.username == username { if user.Username == username {
return user return user
} }
} }