fix code flow example

This commit is contained in:
Livio Amstutz 2022-04-06 11:41:37 +02:00
parent 6736ca0a79
commit 30e40af24a
No known key found for this signature in database
GPG key ID: 26BB1C2FA5952CF0

View file

@ -8,6 +8,7 @@ import (
"time"
"github.com/google/uuid"
"golang.org/x/text/language"
"gopkg.in/square/go-jose.v2"
"github.com/caos/oidc/pkg/oidc"
@ -42,6 +43,20 @@ func NewStorage() *storage {
tokens: make(map[string]*Token),
refreshTokens: make(map[string]*RefreshToken),
clients: clients,
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,
},
},
signingKey: signingKey{
ID: "id",
Algorithm: "RS256",
@ -52,18 +67,16 @@ func NewStorage() *storage {
//CheckUsernamePassword implements the `authenticate` interface of the login
func (s *storage) CheckUsernamePassword(username, password, id string) error {
//for demonstration purposes we'll check on a static list with plain text password
//for real world scenarios, be sure to have the password hashed and salted (e.g. using bcrypt)
user, ok := s.users[username]
if !ok || user.password != password {
return fmt.Errorf("username or password wrong")
}
request, ok := s.authRequests[id]
if !ok {
return fmt.Errorf("request not found")
}
//be sure to set user id into the auth request after the user was checked (either with or without password),
//for demonstration purposes we'll check on a static list with plain text password
//for real world scenarios, be sure to have the password hashed and salted (e.g. using bcrypt)
for _, user := range s.users {
if user.username == username && 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
@ -72,6 +85,9 @@ func (s *storage) CheckUsernamePassword(username, password, id string) error {
//therefore we will also just check this boolean if the request / login has been finished
request.passwordChecked = true
return nil
}
}
return fmt.Errorf("username or password wrong")
}
//CreateAuthRequest implements the op.Storage interface