Documentation
¶
Index ¶
- type AuthnType
- type Client
- func (c *Client) CreateUserWithPassword(ctx context.Context, username, password string, profile UserProfile) (uuid.UUID, error)
- func (c *Client) CreateUserWithSocial(ctx context.Context, provider SocialProvider, subject string, ...) (uuid.UUID, error)
- func (c *Client) DeleteUser(ctx context.Context, id uuid.UUID) error
- func (c *Client) GetUser(ctx context.Context, id uuid.UUID) (*UserResponse, error)
- func (c *Client) GetUserForSocial(ctx context.Context, provider SocialProvider, oidcSubject string) (*UserResponse, error)
- func (c *Client) ListUsers(ctx context.Context, opts ...pagination.Option) (*ListUsersResponse, error)
- func (c *Client) ListUsersForEmail(ctx context.Context, email string, authnType AuthnType) ([]UserResponse, error)
- func (c *Client) Login(ctx context.Context, username, password string) (*LoginResponse, error)
- func (c *Client) LoginWithMFA(ctx context.Context, sessionID, code string) (*LoginResponse, error)
- func (c *Client) UpdateUser(ctx context.Context, id uuid.UUID, req UpdateUserRequest) (*UserResponse, error)
- func (c *Client) UpdateUsernamePassword(ctx context.Context, username, password string) error
- type CreateUserRequest
- type ListUsersResponse
- type LoginResponse
- type LoginStatus
- type MFALoginRequest
- type MutableUserProfile
- type SocialProvider
- type UpdateUserRequest
- type UpdateUsernamePasswordRequest
- type UpdateUsernamePasswordResponse
- type UserAuthn
- type UserProfile
- type UserResponse
- type UsernamePasswordLoginRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthnType ¶
type AuthnType string
AuthnType defines the kinds of authentication factors
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a client to talk to the Userclouds IDP
func NewClient ¶
func NewClient(url string, opts ...jsonclient.Option) (*Client, error)
NewClient constructs a new IDP client
func (*Client) CreateUserWithPassword ¶
func (c *Client) CreateUserWithPassword(ctx context.Context, username, password string, profile UserProfile) (uuid.UUID, error)
CreateUserWithPassword creates a user on the IDP
func (*Client) CreateUserWithSocial ¶
func (c *Client) CreateUserWithSocial(ctx context.Context, provider SocialProvider, subject string, profile UserProfile) (uuid.UUID, error)
CreateUserWithSocial creates a user on the IDP
func (*Client) DeleteUser ¶
DeleteUser deletes a user by ID
func (*Client) GetUserForSocial ¶
func (c *Client) GetUserForSocial(ctx context.Context, provider SocialProvider, oidcSubject string) (*UserResponse, error)
GetUserForSocial gets a user by social provider / ID
func (*Client) ListUsers ¶
func (c *Client) ListUsers(ctx context.Context, opts ...pagination.Option) (*ListUsersResponse, error)
ListUsers lists all users
func (*Client) ListUsersForEmail ¶
func (c *Client) ListUsersForEmail(ctx context.Context, email string, authnType AuthnType) ([]UserResponse, error)
ListUsersForEmail gets all user accounts associated with an email and authn type
func (*Client) LoginWithMFA ¶
LoginWithMFA sends the MFA code response
func (*Client) UpdateUser ¶
func (c *Client) UpdateUser(ctx context.Context, id uuid.UUID, req UpdateUserRequest) (*UserResponse, error)
UpdateUser updates user profile data for a given user ID
type CreateUserRequest ¶
type CreateUserRequest struct {
UserProfile `json:"profile"`
RequireMFA bool `json:"require_mfa"`
UserExtendedProfile userstore.Record `json:"profile_ext"`
UserAuthn
}
CreateUserRequest creates a user on the IDP
type ListUsersResponse ¶
type ListUsersResponse struct {
Data []UserResponse `json:"data"`
pagination.ResponseFields
}
ListUsersResponse is the paginated response from listing users.
type LoginResponse ¶
type LoginResponse struct {
Status LoginStatus `json:"status"`
// UserID is set iff Status == LoginStatusSuccess (TODO: maybe also LoginStatusMFARequired?)
UserID uuid.UUID `json:"user_id"`
// MFAToken is set iff Status == LoginStatusMFARequired
MFAToken string `json:"mfa_token,omitempty"`
}
LoginResponse is the full response returned from an IDP login API
type LoginStatus ¶
type LoginStatus string
LoginStatus indicates whether a login attempt succeeded, failed, or requires additional validation (e.g. MFA)
const ( LoginStatusSuccess LoginStatus = "success" LoginStatusMFARequired LoginStatus = "mfa_required" )
LoginStatus constants
type MFALoginRequest ¶
MFALoginRequest allows the client to submit an MFA code
type MutableUserProfile ¶
type MutableUserProfile struct {
EmailVerified *bool `json:"email_verified,omitempty"`
Name *string `json:"name,omitempty"`
Nickname *string `json:"nickname,omitempty"`
Picture *string `json:"picture,omitempty"`
}
MutableUserProfile is used by UpdateUserRequest to update parts of the core user profile. Only non-nil fields in the underlying struct will be updated.
type SocialProvider ¶
type SocialProvider int
SocialProvider defines the known External/Social Identity Providers
const ( // When sync'ing data from other IDPs, it's possible to encounter social auth providers not yet supported, // in which case we store SocialProviderUnsupported in the DB. SocialProviderUnsupported SocialProvider = -1 // Not having a social provider is the "default", hence why SocialProviderNone is 0. SocialProviderNone SocialProvider = 0 // Valid social auth providers are numbered starting with 1 SocialProviderGoogle SocialProvider = 1 )
SocialProvider constants
func (SocialProvider) MarshalText ¶
func (t SocialProvider) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler (for JSON)
func (SocialProvider) String ¶
func (t SocialProvider) String() string
just here for easier debugging
func (*SocialProvider) UnmarshalText ¶
func (t *SocialProvider) UnmarshalText(b []byte) error
UnmarshalText implements encoding.TextMarshaler (for JSON)
func (SocialProvider) Validate ¶
func (s SocialProvider) Validate() error
Validate implements Validateable
type UpdateUserRequest ¶
type UpdateUserRequest struct {
UserProfile MutableUserProfile `json:"profile"`
// TODO: add MFA factors
RequireMFA *bool `json:"require_mfa,omitempty"`
// Only fields set in the underlying map will be updated
UserExtendedProfile userstore.Record `json:"profile_ext"`
}
UpdateUserRequest optionally updates some or all mutable fields of a user struct. Pointers are used to distinguish between unset vs. set to default value (false, "", etc). TODO: should we allow changing Email? That's a more complex one as there are more implications to changing email that may affect AuthNs and security (e.g. account hijacking, unverified emails, etc).
type UpdateUsernamePasswordRequest ¶
type UpdateUsernamePasswordRequest struct {
Username string `json:"username"`
Password string `json:"password"`
}
UpdateUsernamePasswordRequest is used to keep the follower IDP(s) in sync
type UpdateUsernamePasswordResponse ¶
type UpdateUsernamePasswordResponse struct {
Success bool `json:"success"`
}
UpdateUsernamePasswordResponse confirms an update succeeded (or not)
type UserAuthn ¶
type UserAuthn struct {
AuthnType AuthnType `json:"authn_type"`
// Fields specified if AuthnType == 'password'
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
// Fields specified if AuthnType == 'social'
SocialProvider SocialProvider `json:"social_provider,omitempty"`
OIDCSubject string `json:"oidc_subject,omitempty"`
}
UserAuthn represents an authentication factor for a user. NOTE: some fields are not used in some circumstances, e.g. Password is only used when creating an account but never used when getting an account. TODO: use this for UpdateUser too.
func NewPasswordAuthn ¶
NewPasswordAuthn creates a new UserAuthn for username + password.
func NewSocialAuthn ¶
func NewSocialAuthn(provider SocialProvider, oidcSubject string) UserAuthn
NewSocialAuthn creates a new UserAuthn for social / OIDC login.
type UserProfile ¶
type UserProfile struct {
Email string `json:"email"`
EmailVerified bool `json:"email_verified"`
Name string `json:"name,omitempty"` // Full name in displayable form (incl titles, suffixes, etc) localized to end-user.
Nickname string `json:"nickname,omitempty"` // Casual name of the user, may or may not be same as Given Name.
Picture string `json:"picture,omitempty"` // URL of the user's profile picture.
}
UserProfile is a collection of per-user properties stored in the DB as JSON since they are likely to be sparse and change more frequently. Follow conventions of https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims for all standard fields.
func (*UserProfile) Validate ¶
func (o *UserProfile) Validate() error
Validate implements Validateable
type UserResponse ¶
type UserResponse struct {
ID uuid.UUID `json:"id"`
UpdatedAt int64 `json:"updated_at"` // seconds since the Unix Epoch (UTC)
UserProfile `json:"profile"`
RequireMFA bool `json:"require_mfa"`
UserExtendedProfile userstore.Record `json:"profile_ext"`
Authns []UserAuthn `json:"authns"`
}
UserResponse is the response body for methods which return user data.
type UsernamePasswordLoginRequest ¶
type UsernamePasswordLoginRequest struct {
Username string `json:"username"`
Password string `json:"password"`
}
UsernamePasswordLoginRequest specifies the IDP request to login with username & password.