mirror of
https://github.com/hanzo-fi/go-libs.git
synced 2026-10-30 20:53:44 +00:00
* refactor: move all packages under pkg/ for v5 Move all 13 top-level Go packages into pkg/ for a cleaner repository structure. All internal import paths updated from github.com/formancehq/go-libs/v5/<pkg> to github.com/formancehq/go-libs/v5/pkg/<pkg>. Also includes cleanup: - Fix .golangci.yml stale v4 CircuitBreaker path - Replace deprecated str.Contains with stdlib slices.Contains - Update TODO(v4) markers to TODO - Delete stale coverage.txt - Fix pgtesting timeout not being propagated to docker pool - Update docs/ARCHITECTURE.md to reflect new structure Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore: remove compatibility aliases, unused params, and stub files - Remove unused type aliases (Authenticator, KeySet) from authnfx - Remove unused `debug` parameter from S3ModuleFromFlags - Delete comment-only stub files in messaging/publish/circuit/ Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore: rename cli.go to flags.go for consistency Standardize naming across all packages: cli.go -> flags.go since these files all serve the same purpose (flag definitions). Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore: rename * chore(deps): update all dependencies Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: resolve package name mismatches in generated mocks Generated mock files had stale package names from before the pkg/ move, causing import cycles and build failures with --build-tags it. Co-Authored-By: Claude Opus 4.6 <[email protected]> --------- Co-authored-by: Claude Opus 4.6 <[email protected]>
107 lines
2.9 KiB
Go
107 lines
2.9 KiB
Go
package oidc
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// UserInfo implements OpenID Connect Core 1.0, section 5.1.
|
|
// https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims.
|
|
type UserInfo struct {
|
|
Subject string `json:"sub,omitempty"`
|
|
UserInfoProfile
|
|
UserInfoEmail
|
|
UserInfoPhone
|
|
Address *UserInfoAddress `json:"address,omitempty"`
|
|
|
|
Claims map[string]any `json:"-"`
|
|
}
|
|
|
|
func (u *UserInfo) AppendClaims(k string, v any) {
|
|
if u.Claims == nil {
|
|
u.Claims = make(map[string]any)
|
|
}
|
|
|
|
u.Claims[k] = v
|
|
}
|
|
|
|
// GetAddress is a safe getter that takes
|
|
// care of a possible nil value.
|
|
func (u *UserInfo) GetAddress() *UserInfoAddress {
|
|
if u.Address == nil {
|
|
return new(UserInfoAddress)
|
|
}
|
|
return u.Address
|
|
}
|
|
|
|
// GetSubject implements [rp.SubjectGetter]
|
|
func (u *UserInfo) GetSubject() string {
|
|
return u.Subject
|
|
}
|
|
|
|
type uiAlias UserInfo
|
|
|
|
func (u *UserInfo) MarshalJSON() ([]byte, error) {
|
|
return mergeAndMarshalClaims((*uiAlias)(u), u.Claims)
|
|
}
|
|
|
|
func (u *UserInfo) UnmarshalJSON(data []byte) error {
|
|
return unmarshalJSONMulti(data, (*uiAlias)(u), &u.Claims)
|
|
}
|
|
|
|
type UserInfoProfile struct {
|
|
Name string `json:"name,omitempty"`
|
|
GivenName string `json:"given_name,omitempty"`
|
|
FamilyName string `json:"family_name,omitempty"`
|
|
MiddleName string `json:"middle_name,omitempty"`
|
|
Nickname string `json:"nickname,omitempty"`
|
|
Profile string `json:"profile,omitempty"`
|
|
Picture string `json:"picture,omitempty"`
|
|
Website string `json:"website,omitempty"`
|
|
Gender Gender `json:"gender,omitempty"`
|
|
Birthdate string `json:"birthdate,omitempty"`
|
|
Zoneinfo string `json:"zoneinfo,omitempty"`
|
|
Locale *Locale `json:"locale,omitempty"`
|
|
UpdatedAt Time `json:"updated_at,omitempty"`
|
|
PreferredUsername string `json:"preferred_username,omitempty"`
|
|
}
|
|
|
|
type UserInfoEmail struct {
|
|
Email string `json:"email,omitempty"`
|
|
|
|
// Handle providers that return email_verified as a string
|
|
// https://forums.aws.amazon.com/thread.jspa?messageID=949441󧳁
|
|
// https://discuss.elastic.co/t/openid-error-after-authenticating-against-aws-cognito/206018/11
|
|
EmailVerified Bool `json:"email_verified,omitempty"`
|
|
}
|
|
|
|
type Bool bool
|
|
|
|
func (bs *Bool) UnmarshalJSON(data []byte) error {
|
|
s := strings.Trim(string(data), `"`)
|
|
value, err := strconv.ParseBool(s)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*bs = Bool(value)
|
|
return nil
|
|
}
|
|
|
|
type UserInfoPhone struct {
|
|
PhoneNumber string `json:"phone_number,omitempty"`
|
|
PhoneNumberVerified bool `json:"phone_number_verified,omitempty"`
|
|
}
|
|
|
|
type UserInfoAddress struct {
|
|
Formatted string `json:"formatted,omitempty"`
|
|
StreetAddress string `json:"street_address,omitempty"`
|
|
Locality string `json:"locality,omitempty"`
|
|
Region string `json:"region,omitempty"`
|
|
PostalCode string `json:"postal_code,omitempty"`
|
|
Country string `json:"country,omitempty"`
|
|
}
|
|
|
|
type UserInfoRequest struct {
|
|
AccessToken string `schema:"access_token"`
|
|
}
|