diff --git a/pkg/oidc/types.go b/pkg/oidc/types.go index faf8e7f..0e7152c 100644 --- a/pkg/oidc/types.go +++ b/pkg/oidc/types.go @@ -77,6 +77,10 @@ func (l *Locale) MarshalJSON() ([]byte, error) { return json.Marshal(tag) } +// UnmarshalJSON implements json.Unmarshaler. +// When [language.ValueError] is encountered, the containing tag will be set +// to an empty value (language "und") and no error will be returned. +// This state can be checked with the `l.Tag().IsRoot()` method. func (l *Locale) UnmarshalJSON(data []byte) error { err := json.Unmarshal(data, &l.tag) if err == nil { @@ -86,6 +90,7 @@ func (l *Locale) UnmarshalJSON(data []byte) error { // catch "well-formed but unknown" errors var target language.ValueError if errors.As(err, &target) { + l.tag = language.Tag{} return nil } return err diff --git a/pkg/oidc/userinfo.go b/pkg/oidc/userinfo.go index b824160..ef8ebe4 100644 --- a/pkg/oidc/userinfo.go +++ b/pkg/oidc/userinfo.go @@ -41,13 +41,7 @@ func (u *UserInfo) MarshalJSON() ([]byte, error) { } func (u *UserInfo) UnmarshalJSON(data []byte) error { - if err := unmarshalJSONMulti(data, (*uiAlias)(u), &u.Claims); err != nil { - return err - } - if u.Locale != nil && u.Locale.tag.IsRoot() { - u.Locale = nil - } - return nil + return unmarshalJSONMulti(data, (*uiAlias)(u), &u.Claims) } type UserInfoProfile struct {