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