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
// hashed and salted (e.g. using bcrypt)
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,
// 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
// 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 {
switch scope {
case oidc.ScopeOpenID:
userInfo.SetSubject(user.id)
userInfo.SetSubject(user.ID)
case oidc.ScopeEmail:
userInfo.SetEmail(user.email, user.emailVerified)
userInfo.SetEmail(user.Email, user.EmailVerified)
case oidc.ScopeProfile:
userInfo.SetPreferredUsername(user.username)
userInfo.SetName(user.firstname + " " + user.lastname)
userInfo.SetFamilyName(user.lastname)
userInfo.SetGivenName(user.firstname)
userInfo.SetLocale(user.preferredLanguage)
userInfo.SetPreferredUsername(user.Username)
userInfo.SetName(user.FirstName + " " + user.LastName)
userInfo.SetFamilyName(user.LastName)
userInfo.SetGivenName(user.FirstName)
userInfo.SetLocale(user.PreferredLanguage)
case oidc.ScopePhone:
userInfo.SetPhone(user.phone, user.phoneVerified)
userInfo.SetPhone(user.Phone, user.PhoneVerified)
case CustomScope:
// you can also have a custom scope and assert public or custom claims based on that
userInfo.AppendClaims(CustomClaim, customClaim(clientID))

View file

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