mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-20 23:07:33 +00:00
e00cc187fa
* fix: make user creation errors helpful * fix linting and unit testing errors * fix linting * make zitadel config reusable * fix human validations * translate ssr errors * make zitadel config reusable * cover more translations for ssr * handle email validation message centrally * fix unit tests * fix linting * align signatures * use more precise wording * handle phone validation message centrally * fix: return specific profile errors * docs: edit comments * fix unit tests --------- Co-authored-by: Silvan <silvan.reusser@gmail.com>
111 lines
2.5 KiB
Go
111 lines
2.5 KiB
Go
package oauth
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"golang.org/x/text/language"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/idp"
|
|
)
|
|
|
|
var _ idp.User = (*UserMapper)(nil)
|
|
|
|
// UserMapper is an implementation of [idp.User].
|
|
// It can be used in ZITADEL actions to map the `RawInfo`
|
|
type UserMapper struct {
|
|
idAttribute string
|
|
RawInfo map[string]interface{}
|
|
}
|
|
|
|
func NewUserMapper(idAttribute string) *UserMapper {
|
|
return &UserMapper{
|
|
idAttribute: idAttribute,
|
|
RawInfo: make(map[string]interface{}),
|
|
}
|
|
}
|
|
|
|
func (u *UserMapper) UnmarshalJSON(data []byte) error {
|
|
return json.Unmarshal(data, &u.RawInfo)
|
|
}
|
|
|
|
// GetID is an implementation of the [idp.User] interface.
|
|
func (u *UserMapper) GetID() string {
|
|
id, ok := u.RawInfo[u.idAttribute]
|
|
if !ok {
|
|
return ""
|
|
}
|
|
switch i := id.(type) {
|
|
case string:
|
|
return i
|
|
case int:
|
|
return strconv.Itoa(i)
|
|
case float64:
|
|
return strconv.FormatFloat(i, 'f', -1, 64)
|
|
default:
|
|
return fmt.Sprint(i)
|
|
}
|
|
}
|
|
|
|
// GetFirstName is an implementation of the [idp.User] interface.
|
|
func (u *UserMapper) GetFirstName() string {
|
|
return ""
|
|
}
|
|
|
|
// GetLastName is an implementation of the [idp.User] interface.
|
|
func (u *UserMapper) GetLastName() string {
|
|
return ""
|
|
}
|
|
|
|
// GetDisplayName is an implementation of the [idp.User] interface.
|
|
func (u *UserMapper) GetDisplayName() string {
|
|
return ""
|
|
}
|
|
|
|
// GetNickname is an implementation of the [idp.User] interface.
|
|
func (u *UserMapper) GetNickname() string {
|
|
return ""
|
|
}
|
|
|
|
// GetPreferredUsername is an implementation of the [idp.User] interface.
|
|
func (u *UserMapper) GetPreferredUsername() string {
|
|
return ""
|
|
}
|
|
|
|
// GetEmail is an implementation of the [idp.User] interface.
|
|
func (u *UserMapper) GetEmail() domain.EmailAddress {
|
|
return ""
|
|
}
|
|
|
|
// IsEmailVerified is an implementation of the [idp.User] interface.
|
|
func (u *UserMapper) IsEmailVerified() bool {
|
|
return false
|
|
}
|
|
|
|
// GetPhone is an implementation of the [idp.User] interface.
|
|
func (u *UserMapper) GetPhone() domain.PhoneNumber {
|
|
return ""
|
|
}
|
|
|
|
// IsPhoneVerified is an implementation of the [idp.User] interface.
|
|
func (u *UserMapper) IsPhoneVerified() bool {
|
|
return false
|
|
}
|
|
|
|
// GetPreferredLanguage is an implementation of the [idp.User] interface.
|
|
func (u *UserMapper) GetPreferredLanguage() language.Tag {
|
|
return language.Und
|
|
}
|
|
|
|
// GetAvatarURL is an implementation of the [idp.User] interface.
|
|
func (u *UserMapper) GetAvatarURL() string {
|
|
return ""
|
|
}
|
|
|
|
// GetProfile is an implementation of the [idp.User] interface.
|
|
func (u *UserMapper) GetProfile() string {
|
|
return ""
|
|
}
|