2023-01-23 07:11:40 +00:00
|
|
|
package oauth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2023-03-03 10:38:49 +00:00
|
|
|
"fmt"
|
|
|
|
"strconv"
|
2023-01-23 07:11:40 +00:00
|
|
|
|
|
|
|
"golang.org/x/text/language"
|
|
|
|
|
2023-03-14 19:20:38 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2023-01-23 07:11:40 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/idp"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ idp.User = (*UserMapper)(nil)
|
|
|
|
|
|
|
|
// UserMapper is an implementation of [idp.User].
|
2023-03-03 10:38:49 +00:00
|
|
|
// It can be used in ZITADEL actions to map the `RawInfo`
|
2023-01-23 07:11:40 +00:00
|
|
|
type UserMapper struct {
|
2023-03-03 10:38:49 +00:00
|
|
|
idAttribute string
|
|
|
|
RawInfo map[string]interface{}
|
2023-01-23 07:11:40 +00:00
|
|
|
}
|
|
|
|
|
2023-03-03 10:38:49 +00:00
|
|
|
func NewUserMapper(idAttribute string) *UserMapper {
|
|
|
|
return &UserMapper{
|
|
|
|
idAttribute: idAttribute,
|
|
|
|
RawInfo: make(map[string]interface{}),
|
2023-01-23 07:11:40 +00:00
|
|
|
}
|
2023-03-03 10:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (u *UserMapper) UnmarshalJSON(data []byte) error {
|
|
|
|
return json.Unmarshal(data, &u.RawInfo)
|
2023-01-23 07:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetID is an implementation of the [idp.User] interface.
|
|
|
|
func (u *UserMapper) GetID() string {
|
2023-03-03 10:38:49 +00:00
|
|
|
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)
|
|
|
|
}
|
2023-01-23 07:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetFirstName is an implementation of the [idp.User] interface.
|
|
|
|
func (u *UserMapper) GetFirstName() string {
|
2023-03-03 10:38:49 +00:00
|
|
|
return ""
|
2023-01-23 07:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetLastName is an implementation of the [idp.User] interface.
|
|
|
|
func (u *UserMapper) GetLastName() string {
|
2023-03-03 10:38:49 +00:00
|
|
|
return ""
|
2023-01-23 07:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetDisplayName is an implementation of the [idp.User] interface.
|
|
|
|
func (u *UserMapper) GetDisplayName() string {
|
2023-03-03 10:38:49 +00:00
|
|
|
return ""
|
2023-01-23 07:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetNickname is an implementation of the [idp.User] interface.
|
|
|
|
func (u *UserMapper) GetNickname() string {
|
2023-03-03 10:38:49 +00:00
|
|
|
return ""
|
2023-01-23 07:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetPreferredUsername is an implementation of the [idp.User] interface.
|
|
|
|
func (u *UserMapper) GetPreferredUsername() string {
|
2023-03-03 10:38:49 +00:00
|
|
|
return ""
|
2023-01-23 07:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetEmail is an implementation of the [idp.User] interface.
|
2023-03-14 19:20:38 +00:00
|
|
|
func (u *UserMapper) GetEmail() domain.EmailAddress {
|
2023-03-03 10:38:49 +00:00
|
|
|
return ""
|
2023-01-23 07:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsEmailVerified is an implementation of the [idp.User] interface.
|
|
|
|
func (u *UserMapper) IsEmailVerified() bool {
|
2023-03-03 10:38:49 +00:00
|
|
|
return false
|
2023-01-23 07:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetPhone is an implementation of the [idp.User] interface.
|
2023-03-14 19:20:38 +00:00
|
|
|
func (u *UserMapper) GetPhone() domain.PhoneNumber {
|
2023-03-03 10:38:49 +00:00
|
|
|
return ""
|
2023-01-23 07:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsPhoneVerified is an implementation of the [idp.User] interface.
|
|
|
|
func (u *UserMapper) IsPhoneVerified() bool {
|
2023-03-03 10:38:49 +00:00
|
|
|
return false
|
2023-01-23 07:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetPreferredLanguage is an implementation of the [idp.User] interface.
|
|
|
|
func (u *UserMapper) GetPreferredLanguage() language.Tag {
|
2023-03-03 10:38:49 +00:00
|
|
|
return language.Und
|
2023-01-23 07:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetAvatarURL is an implementation of the [idp.User] interface.
|
|
|
|
func (u *UserMapper) GetAvatarURL() string {
|
2023-03-03 10:38:49 +00:00
|
|
|
return ""
|
2023-01-23 07:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetProfile is an implementation of the [idp.User] interface.
|
|
|
|
func (u *UserMapper) GetProfile() string {
|
2023-03-03 10:38:49 +00:00
|
|
|
return ""
|
2023-01-23 07:11:40 +00:00
|
|
|
}
|