Documentation ¶
Overview ¶
Package users provides a client wrapping the WorkOS User Management API.
Index ¶
- Constants
- Variables
- func DeleteUser(ctx context.Context, opts DeleteUserOpts) error
- func SetAPIKey(apiKey string)
- type AddUserToOrganizationOpts
- type AuthenticateWithCodeOpts
- type AuthenticateWithMagicAuthOpts
- type AuthenticateWithPasswordOpts
- type AuthenticateWithTOTPOpts
- type AuthenticationResponse
- type AuthorizedOrganization
- type Client
- func (c *Client) AddUserToOrganization(ctx context.Context, opts AddUserToOrganizationOpts) (User, error)
- func (c *Client) AuthenticateWithCode(ctx context.Context, opts AuthenticateWithCodeOpts) (UserResponse, error)
- func (c *Client) AuthenticateWithMagicAuth(ctx context.Context, opts AuthenticateWithMagicAuthOpts) (UserResponse, error)
- func (c *Client) AuthenticateWithPassword(ctx context.Context, opts AuthenticateWithPasswordOpts) (UserResponse, error)
- func (c *Client) AuthenticateWithTOTP(ctx context.Context, opts AuthenticateWithTOTPOpts) (UserResponse, error)
- func (c *Client) CreateUser(ctx context.Context, opts CreateUserOpts) (User, error)
- func (c *Client) DeleteUser(ctx context.Context, opts DeleteUserOpts) error
- func (c *Client) EnrollAuthFactor(ctx context.Context, opts EnrollAuthFactorOpts) (AuthenticationResponse, error)
- func (c *Client) GetUser(ctx context.Context, opts GetUserOpts) (User, error)
- func (c *Client) ListAuthFactors(ctx context.Context, opts ListAuthFactorsOpts) (ListAuthFactorsResponse, error)
- func (c *Client) ListUsers(ctx context.Context, opts ListUsersOpts) (ListUsersResponse, error)
- func (c *Client) RemoveUserFromOrganization(ctx context.Context, opts RemoveUserFromOrganizationOpts) (User, error)
- func (c *Client) ResetPassword(ctx context.Context, opts ResetPasswordOpts) (UserResponse, error)
- func (c *Client) SendMagicAuthCode(ctx context.Context, opts SendMagicAuthCodeOpts) (UserResponse, error)
- func (c *Client) SendPasswordResetEmail(ctx context.Context, opts SendPasswordResetEmailOpts) (UserResponse, error)
- func (c *Client) SendVerificationEmail(ctx context.Context, opts SendVerificationEmailOpts) (UserResponse, error)
- func (c *Client) UpdateUser(ctx context.Context, opts UpdateUserOpts) (User, error)
- func (c *Client) UpdateUserPassword(ctx context.Context, opts UpdateUserPasswordOpts) (User, error)
- func (c *Client) VerifyEmailCode(ctx context.Context, opts VerifyEmailCodeOpts) (UserResponse, error)
- type CreateUserOpts
- type DeleteUserOpts
- type EnrollAuthFactorOpts
- type GetUserOpts
- type ListAuthFactorsOpts
- type ListAuthFactorsResponse
- type ListUsersOpts
- type ListUsersResponse
- type MagicAuthChallengeID
- type Order
- type Organization
- type OrganizationMembership
- type RemoveUserFromOrganizationOpts
- type ResetPasswordOpts
- type SendMagicAuthCodeOpts
- type SendPasswordResetEmailOpts
- type SendVerificationEmailOpts
- type UpdateUserOpts
- type UpdateUserPasswordOpts
- type User
- func AddUserToOrganization(ctx context.Context, opts AddUserToOrganizationOpts) (User, error)
- func CreateUser(ctx context.Context, opts CreateUserOpts) (User, error)
- func GetUser(ctx context.Context, opts GetUserOpts) (User, error)
- func RemoveUserFromOrganization(ctx context.Context, opts RemoveUserFromOrganizationOpts) (User, error)
- func UpdateUser(ctx context.Context, opts UpdateUserOpts) (User, error)
- func UpdateUserPassword(ctx context.Context, opts UpdateUserPasswordOpts) (User, error)
- type UserResponse
- func AuthenticateWithCode(ctx context.Context, opts AuthenticateWithCodeOpts) (UserResponse, error)
- func AuthenticateWithMagicAuth(ctx context.Context, opts AuthenticateWithMagicAuthOpts) (UserResponse, error)
- func AuthenticateWithPassword(ctx context.Context, opts AuthenticateWithPasswordOpts) (UserResponse, error)
- func AuthenticateWithTOTP(ctx context.Context, opts AuthenticateWithTOTPOpts) (UserResponse, error)
- func ResetPassword(ctx context.Context, opts ResetPasswordOpts) (UserResponse, error)
- func SendMagicAuthCode(ctx context.Context, opts SendMagicAuthCodeOpts) (UserResponse, error)
- func SendPasswordResetEmail(ctx context.Context, opts SendPasswordResetEmailOpts) (UserResponse, error)
- func SendVerificationEmail(ctx context.Context, opts SendVerificationEmailOpts) (UserResponse, error)
- func VerifyEmailCode(ctx context.Context, opts VerifyEmailCodeOpts) (UserResponse, error)
- type VerifyEmailCodeOpts
Constants ¶
const ResponseLimit = 10
ResponseLimit is the default number of records to limit a response to.
Variables ¶
var ( // DefaultClient is the client used by User management methods DefaultClient = NewClient("") )
Functions ¶
func DeleteUser ¶ added in v2.3.0
func DeleteUser( ctx context.Context, opts DeleteUserOpts, ) error
DeleteUser deletes a existing User.
Types ¶
type AuthenticateWithCodeOpts ¶ added in v2.3.0
type AuthenticateWithMagicAuthOpts ¶ added in v2.3.0
type AuthenticateWithPasswordOpts ¶ added in v2.3.0
type AuthenticateWithTOTPOpts ¶ added in v2.3.0
type AuthenticateWithTOTPOpts struct { ClientID string `json:"client_id"` Code string `json:"code"` IPAddress string `json:"ip_address,omitempty"` UserAgent string `json:"user_agent,omitempty"` PendingAuthenticationToken string `json:"pending_authentication_token"` AuthenticationChallengeID string `json:"authentication_challenge_id"` }
type AuthenticationResponse ¶
type AuthenticationResponse struct { Factor mfa.Factor `json:"authentication_factor"` Challenge mfa.Challenge `json:"authentication_challenge"` }
func EnrollAuthFactor ¶ added in v2.3.0
func EnrollAuthFactor( ctx context.Context, opts EnrollAuthFactorOpts, ) (AuthenticationResponse, error)
EnrollAuthFactor enrolls an authentication factor for the user.
type AuthorizedOrganization ¶
type AuthorizedOrganization struct {
Organization Organization `json:"organization"`
}
type Client ¶
type Client struct { // The WorkOS api key. It can be found in // https://dashboard.workos.com/api-keys. // // REQUIRED. APIKey string // The http.Client that is used to send request to WorkOS. // // Defaults to http.Client. HTTPClient *http.Client // The endpoint to WorkOS API. // // Defaults to https://api.workos.com. Endpoint string // The function used to encode in JSON. Defaults to json.Marshal. JSONEncode func(v interface{}) ([]byte, error) }
Client represents a client that fetch User Management data from WorkOS API.
func (*Client) AddUserToOrganization ¶
func (c *Client) AddUserToOrganization(ctx context.Context, opts AddUserToOrganizationOpts) (User, error)
AddUserToOrganization adds an unmanaged user to an Organization
func (*Client) AuthenticateWithCode ¶ added in v2.3.0
func (c *Client) AuthenticateWithCode(ctx context.Context, opts AuthenticateWithCodeOpts) (UserResponse, error)
AuthenticateWithCode authenticates an OAuth user or a managed SSO user that is logging in through SSO
func (*Client) AuthenticateWithMagicAuth ¶ added in v2.3.0
func (c *Client) AuthenticateWithMagicAuth(ctx context.Context, opts AuthenticateWithMagicAuthOpts) (UserResponse, error)
AuthenticateWithMagicAuth authenticates a user by verifying a one-time code sent to the user's email address by the Magic Auth Send Code endpoint.
func (*Client) AuthenticateWithPassword ¶ added in v2.3.0
func (c *Client) AuthenticateWithPassword(ctx context.Context, opts AuthenticateWithPasswordOpts) (UserResponse, error)
AuthenticateWithPassword authenticates a user with Email and Password
func (*Client) AuthenticateWithTOTP ¶ added in v2.3.0
func (c *Client) AuthenticateWithTOTP(ctx context.Context, opts AuthenticateWithTOTPOpts) (UserResponse, error)
AuthenticateWithTOTP authenticates a user by verifying a time-based one-time password (TOTP)
func (*Client) CreateUser ¶
CreateUser create a new user with email password authentication. Only unmanaged users can be created directly using the User Management API.
func (*Client) DeleteUser ¶ added in v2.3.0
func (c *Client) DeleteUser(ctx context.Context, opts DeleteUserOpts) error
DeleteUser delete an existing user.
func (*Client) EnrollAuthFactor ¶ added in v2.3.0
func (c *Client) EnrollAuthFactor(ctx context.Context, opts EnrollAuthFactorOpts) (AuthenticationResponse, error)
EnrollAuthFactor enrolls an authentication factor for the user.
func (*Client) ListAuthFactors ¶ added in v2.3.0
func (c *Client) ListAuthFactors(ctx context.Context, opts ListAuthFactorsOpts) (ListAuthFactorsResponse, error)
ListAuthFactors lists the available authentication factors for the user.
func (*Client) ListUsers ¶
func (c *Client) ListUsers(ctx context.Context, opts ListUsersOpts) (ListUsersResponse, error)
ListUsers get a list of all of your existing users matching the criteria specified.
func (*Client) RemoveUserFromOrganization ¶
func (c *Client) RemoveUserFromOrganization(ctx context.Context, opts RemoveUserFromOrganizationOpts) (User, error)
RemoveUserFromOrganization removes an unmanaged User from the given Organization.
func (*Client) ResetPassword ¶ added in v2.3.0
func (c *Client) ResetPassword(ctx context.Context, opts ResetPasswordOpts) (UserResponse, error)
ResetPassword resets user password using token that was sent to the user.
func (*Client) SendMagicAuthCode ¶
func (c *Client) SendMagicAuthCode(ctx context.Context, opts SendMagicAuthCodeOpts) (UserResponse, error)
SendMagicAuthCode creates a one-time Magic Auth code and emails it to the user.
func (*Client) SendPasswordResetEmail ¶ added in v2.3.0
func (c *Client) SendPasswordResetEmail(ctx context.Context, opts SendPasswordResetEmailOpts) (UserResponse, error)
SendPasswordResetEmail creates a password reset challenge and emails a password reset link to an unmanaged user.
func (*Client) SendVerificationEmail ¶ added in v2.3.0
func (c *Client) SendVerificationEmail(ctx context.Context, opts SendVerificationEmailOpts) (UserResponse, error)
SendVerificationEmail creates an email verification challenge and emails verification token to user.
func (*Client) UpdateUser ¶ added in v2.3.0
UpdateUser updates User attributes.
func (*Client) UpdateUserPassword ¶ added in v2.3.0
UpdateUserPassword updates a User password.
func (*Client) VerifyEmailCode ¶ added in v2.3.0
func (c *Client) VerifyEmailCode(ctx context.Context, opts VerifyEmailCodeOpts) (UserResponse, error)
VerifyEmailCode verifies user email using verification token that was sent to the user.
type CreateUserOpts ¶
type DeleteUserOpts ¶ added in v2.3.0
type DeleteUserOpts struct {
User string
}
type EnrollAuthFactorOpts ¶ added in v2.3.0
type EnrollAuthFactorOpts struct { User string Type mfa.FactorType `json:"type"` TOTPIssuer string `json:"totp_issuer,omitempty"` TOTPUser string `json:"totp_user,omitempty"` }
type GetUserOpts ¶
type GetUserOpts struct { // User unique identifier User string `json:"id"` }
GetUserOpts contains the options to pass in order to get a user profile.
type ListAuthFactorsOpts ¶ added in v2.3.0
type ListAuthFactorsOpts struct {
User string
}
type ListAuthFactorsResponse ¶ added in v2.3.0
type ListAuthFactorsResponse struct { Data []mfa.Factor `json:"data"` ListMetadata common.ListMetadata `json:"list_metadata"` }
func ListAuthFactors ¶ added in v2.3.0
func ListAuthFactors( ctx context.Context, opts ListAuthFactorsOpts, ) (ListAuthFactorsResponse, error)
ListAuthFactors lists the available authentication factors for the user.
type ListUsersOpts ¶
type ListUsersOpts struct { // Filter Users by their email. Email string `url:"email,omitempty"` // Filter Users by the organization they are members of. Organization string `url:"organization,omitempty"` // Maximum number of records to return. Limit int `url:"limit"` // The order in which to paginate records. Order Order `url:"order,omitempty"` // Pagination cursor to receive records before a provided User ID. Before string `url:"before,omitempty"` // Pagination cursor to receive records after a provided User ID. After string `url:"after,omitempty"` }
type ListUsersResponse ¶
type ListUsersResponse struct { // List of Users Data []User `json:"data"` // Cursor to paginate through the list of Users ListMetadata common.ListMetadata `json:"list_metadata"` }
ListUsersResponse contains the response from the ListUsers call.
func ListUsers ¶
func ListUsers( ctx context.Context, opts ListUsersOpts, ) (ListUsersResponse, error)
ListUsers gets a list of Users.
type MagicAuthChallengeID ¶
type MagicAuthChallengeID string
type Organization ¶
type Organization struct { // The Organization's unique identifier. ID string `json:"id"` // The Organization's name. Name string `json:"name"` }
Organization contains data about a particular Organization.
type OrganizationMembership ¶
type OrganizationMembership struct { // Contains the ID and name of the associated Organization. Organization Organization `json:"organization"` // CreatedAt is the timestamp of when the OrganizationMembership was created. CreatedAt string `json:"created_at"` // UpdatedAt is the timestamp of when the OrganizationMembership was updated. UpdatedAt string `json:"updated_at"` }
OrganizationMembership contains data about a particular OrganizationMembership.
type ResetPasswordOpts ¶ added in v2.3.0
type SendMagicAuthCodeOpts ¶
type SendMagicAuthCodeOpts struct { // The email address the one-time code will be sent to. Email string `json:"email"` }
type SendPasswordResetEmailOpts ¶ added in v2.3.0
type SendVerificationEmailOpts ¶ added in v2.3.0
type SendVerificationEmailOpts struct { // The unique ID of the User whose email address will be verified. User string }
type UpdateUserOpts ¶ added in v2.3.0
type UpdateUserPasswordOpts ¶ added in v2.3.0
type User ¶
type User struct { // The User's unique identifier. ID string `json:"id"` // The User's first name. FirstName string `json:"first_name"` // The User's last name. LastName string `json:"last_name"` // The User's email. Email string `json:"email"` // The timestamp of when the User was created. CreatedAt string `json:"created_at"` // The timestamp of when the User was updated. UpdatedAt string `json:"updated_at"` // Whether the User email is verified. EmailVerified bool `json:"email_verified"` }
User contains data about a particular User.
func AddUserToOrganization ¶
func AddUserToOrganization( ctx context.Context, opts AddUserToOrganizationOpts, ) (User, error)
AddUserToOrganization adds an unmanaged User as a member of the given Organization.
func CreateUser ¶
func CreateUser( ctx context.Context, opts CreateUserOpts, ) (User, error)
CreateUser creates a User.
func GetUser ¶
func GetUser( ctx context.Context, opts GetUserOpts, ) (User, error)
GetUser gets a User.
func RemoveUserFromOrganization ¶
func RemoveUserFromOrganization( ctx context.Context, opts RemoveUserFromOrganizationOpts, ) (User, error)
RemoveUserFromOrganization removes an unmanaged User as a member of the given Organization.
func UpdateUser ¶ added in v2.3.0
func UpdateUser( ctx context.Context, opts UpdateUserOpts, ) (User, error)
UpdateUser creates a User.
func UpdateUserPassword ¶ added in v2.3.0
func UpdateUserPassword( ctx context.Context, opts UpdateUserPasswordOpts, ) (User, error)
UpdateUserPassword updates a User password.
type UserResponse ¶ added in v2.3.0
type UserResponse struct {
User User `json:"user"`
}
func AuthenticateWithCode ¶ added in v2.3.0
func AuthenticateWithCode( ctx context.Context, opts AuthenticateWithCodeOpts, ) (UserResponse, error)
AuthenticateWithCode authenticates an OAuth user or a managed SSO user that is logging in through SSO, and optionally creates a session.
func AuthenticateWithMagicAuth ¶ added in v2.3.0
func AuthenticateWithMagicAuth( ctx context.Context, opts AuthenticateWithMagicAuthOpts, ) (UserResponse, error)
AuthenticateWithMagicAuth authenticates a user by verifying a one-time code sent to the user's email address by the Magic Auth Send Code endpoint.
func AuthenticateWithPassword ¶ added in v2.3.0
func AuthenticateWithPassword( ctx context.Context, opts AuthenticateWithPasswordOpts, ) (UserResponse, error)
AuthenticateWithPassword authenticates a user with email and password and optionally creates a session.
func AuthenticateWithTOTP ¶ added in v2.3.0
func AuthenticateWithTOTP( ctx context.Context, opts AuthenticateWithTOTPOpts, ) (UserResponse, error)
AuthenticateWithTOTP authenticates a user by verifying a time-based one-time password (TOTP)
func ResetPassword ¶ added in v2.3.0
func ResetPassword( ctx context.Context, opts ResetPasswordOpts, ) (UserResponse, error)
ResetPassword resets user password using token that was sent to the user.
func SendMagicAuthCode ¶
func SendMagicAuthCode( ctx context.Context, opts SendMagicAuthCodeOpts, ) (UserResponse, error)
SendMagicAuthCode sends a one-time code to the user's email address.
func SendPasswordResetEmail ¶ added in v2.3.0
func SendPasswordResetEmail( ctx context.Context, opts SendPasswordResetEmailOpts, ) (UserResponse, error)
SendPasswordResetEmail creates a password reset challenge and emails a password reset link to an unmanaged user.
func SendVerificationEmail ¶ added in v2.3.0
func SendVerificationEmail( ctx context.Context, opts SendVerificationEmailOpts, ) (UserResponse, error)
SendVerificationEmail creates an email verification challenge and emails verification token to user.
func VerifyEmailCode ¶ added in v2.3.0
func VerifyEmailCode( ctx context.Context, opts VerifyEmailCodeOpts, ) (UserResponse, error)
VerifyEmailCode verifies user email using verification token that was sent to the user.