From bedfb2f07c4040898643be696bf887da9635dcc6 Mon Sep 17 00:00:00 2001 From: alex-stytch Date: Tue, 25 Apr 2023 14:26:33 -0700 Subject: [PATCH 01/12] Add B2B endpoints --- stytch/b2b/b2bstytchapi/b2bstytchapi.go | 45 ++++++++++++ stytch/b2b/magiclink.go | 46 ++++++++++++ stytch/b2b/magiclink/email/email.go | 36 ++++++++++ stytch/b2b/magiclink/magiclink.go | 38 ++++++++++ stytch/b2b/organization.go | 46 ++++++++++++ stytch/b2b/session.go | 4 ++ stytch/{ => b2c}/attributes.go | 2 +- stytch/{ => b2c}/cryptowallet.go | 2 +- stytch/{ => b2c}/cryptowallet/cryptowallet.go | 23 +++--- stytch/{ => b2c}/magiclink.go | 2 +- stytch/{ => b2c}/magiclink/email/email.go | 25 +++---- stytch/{ => b2c}/magiclink/magiclink.go | 25 +++---- stytch/{ => b2c}/oauth.go | 2 +- stytch/{ => b2c}/oauth/oauth.go | 25 +++---- stytch/{ => b2c}/otp.go | 2 +- stytch/{ => b2c}/otp/email/email.go | 13 ++-- stytch/{ => b2c}/otp/otp.go | 23 +++--- stytch/{ => b2c}/otp/sms/sms.go | 13 ++-- stytch/{ => b2c}/otp/whatsapp/whatsapp.go | 13 ++-- stytch/{ => b2c}/password.go | 2 +- stytch/{ => b2c}/password/email/email.go | 23 +++--- .../existingpassword/existingpassword.go | 17 ++--- stytch/{ => b2c}/password/password.go | 51 ++++++------- stytch/{ => b2c}/password/session/session.go | 7 +- stytch/{ => b2c}/session.go | 2 +- stytch/{ => b2c}/session/session.go | 57 +++++++-------- stytch/{ => b2c}/session/session_test.go | 39 +++++----- stytch/{ => b2c}/stytchapi/stytchapi.go | 32 ++++----- stytch/{ => b2c}/stytchapi/stytchapi_test.go | 5 +- stytch/{ => b2c}/totp.go | 2 +- stytch/{ => b2c}/totp/totp.go | 43 +++++------ stytch/{ => b2c}/user.go | 2 +- stytch/{ => b2c}/user/user.go | 71 ++++++++++--------- stytch/{ => b2c}/webauthn.go | 2 +- stytch/{ => b2c}/webauthn/webauthn.go | 35 ++++----- 35 files changed, 504 insertions(+), 271 deletions(-) create mode 100644 stytch/b2b/b2bstytchapi/b2bstytchapi.go create mode 100644 stytch/b2b/magiclink.go create mode 100644 stytch/b2b/magiclink/email/email.go create mode 100644 stytch/b2b/magiclink/magiclink.go create mode 100644 stytch/b2b/organization.go create mode 100644 stytch/b2b/session.go rename stytch/{ => b2c}/attributes.go (99%) rename stytch/{ => b2c}/cryptowallet.go (99%) rename stytch/{ => b2c}/cryptowallet/cryptowallet.go (81%) rename stytch/{ => b2c}/magiclink.go (99%) rename stytch/{ => b2c}/magiclink/email/email.go (77%) rename stytch/{ => b2c}/magiclink/magiclink.go (81%) rename stytch/{ => b2c}/oauth.go (99%) rename stytch/{ => b2c}/oauth/oauth.go (82%) rename stytch/{ => b2c}/otp.go (99%) rename stytch/{ => b2c}/otp/email/email.go (78%) rename stytch/{ => b2c}/otp/otp.go (79%) rename stytch/{ => b2c}/otp/sms/sms.go (79%) rename stytch/{ => b2c}/otp/whatsapp/whatsapp.go (77%) rename stytch/{ => b2c}/password.go (99%) rename stytch/{ => b2c}/password/email/email.go (82%) rename stytch/{ => b2c}/password/existingpassword/existingpassword.go (82%) rename stytch/{ => b2c}/password/password.go (80%) rename stytch/{ => b2c}/password/session/session.go (78%) rename stytch/{ => b2c}/session.go (99%) rename stytch/{ => b2c}/session/session.go (81%) rename stytch/{ => b2c}/session/session_test.go (93%) rename stytch/{ => b2c}/stytchapi/stytchapi.go (74%) rename stytch/{ => b2c}/stytchapi/stytchapi_test.go (91%) rename stytch/{ => b2c}/totp.go (99%) rename stytch/{ => b2c}/totp/totp.go (81%) rename stytch/{ => b2c}/user.go (99%) rename stytch/{ => b2c}/user/user.go (74%) rename stytch/{ => b2c}/webauthn.go (99%) rename stytch/{ => b2c}/webauthn/webauthn.go (80%) diff --git a/stytch/b2b/b2bstytchapi/b2bstytchapi.go b/stytch/b2b/b2bstytchapi/b2bstytchapi.go new file mode 100644 index 0000000..5adfdbc --- /dev/null +++ b/stytch/b2b/b2bstytchapi/b2bstytchapi.go @@ -0,0 +1,45 @@ +package b2bstytchapi + +import ( + "github.com/stytchauth/stytch-go/v7/stytch" + "github.com/stytchauth/stytch-go/v7/stytch/b2b/magiclink" + mle "github.com/stytchauth/stytch-go/v7/stytch/b2b/magiclink/email" + "github.com/stytchauth/stytch-go/v7/stytch/config" +) + +type Logger interface { + Printf(format string, v ...interface{}) +} + +type API struct { + client *stytch.Client + logger Logger + MagicLinks *magiclink.Client +} + +type Option func(*API) + +func WithLogger(logger Logger) Option { + return func(api *API) { api.logger = logger } +} + +// WithBaseURI overrides the client base URI determined by the environment. +// +// The value derived from stytch.EnvLive or stytch.EnvTest is already correct for production use +// in the Live or Test environment, respectively. This is implemented to make it easier to use +// this client to access internal development versions of the API. +func WithBaseURI(uri string) Option { + return func(api *API) { api.client.Config.BaseURI = config.BaseURI(uri) } +} + +func NewAPIClient(env config.Env, projectID string, secret string, opts ...Option) (*API, error) { + a := &API{ + client: stytch.New(env, projectID, secret), + } + for _, o := range opts { + o(a) + } + + a.MagicLinks = &magiclink.Client{C: a.client, Email: &mle.Client{C: a.client}} + return a, nil +} diff --git a/stytch/b2b/magiclink.go b/stytch/b2b/magiclink.go new file mode 100644 index 0000000..cead785 --- /dev/null +++ b/stytch/b2b/magiclink.go @@ -0,0 +1,46 @@ +package b2b + +type MagicLinksAuthenticateParams struct { + MagicLinksToken string `json:"magic_links_token"` + SessionToken string `json:"session_token,omitempty"` + SessionJWT string `json:"session_jwt,omitempty"` + SessionDurationMinutes int32 `json:"session_duration_minutes,omitempty"` + SessionCustomClaims map[string]interface{} `json:"session_custom_claims,omitempty"` + PKCECodeVerifier string `json:"pkce_code_verifier,omitempty"` +} + +type MagicLinksAuthenticateResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + MemberID string `json:"member_id,omitempty"` + MethodID string `json:"method_id,omitempty"` + ResetSessions bool `json:"reset_sessions,omitempty"` + OrganizationID string `json:"organization_id,omitempty"` + Member Member `json:"member,omitempty"` + SessionToken string `json:"session_token,omitempty"` + SessionJWT string `json:"session_jwt,omitempty"` + MemberSession MemberSession `json:"member_session,omitempty"` + Organization Organization `json:"organization,omitempty"` +} + +// MAGIC LINK - EMAIL +type MagicLinksEmailLoginOrSignupParams struct { + OrganizationID string `json:"organization_id"` + EmailAddress string `json:"email_address"` + LoginMagicLinkURL string `json:"login_magic_link_url,omitempty"` + SignupMagicLinkURL string `json:"signup_magic_link_url,omitempty"` + LoginExpirationMinutes int32 `json:"login_expiration_minutes,omitempty"` + PKCECodeChallenge string `json:"pkce_code_challenge,omitempty"` + LoginTemplateID string `json:"login_template_id,omitempty"` + SignupTemplateID string `json:"signup_template_id,omitempty"` + Locale string `json:"locale,omitempty"` +} + +type MagicLinksEmailLoginOrSignupResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + MemberID string `json:"member_id,omitempty"` + MemberCreated bool `json:"member_created,omitempty"` + Member Member `json:"member,omitempty"` + Organization Organization `json:"organization,omitempty"` +} diff --git a/stytch/b2b/magiclink/email/email.go b/stytch/b2b/magiclink/email/email.go new file mode 100644 index 0000000..69c438d --- /dev/null +++ b/stytch/b2b/magiclink/email/email.go @@ -0,0 +1,36 @@ +package email + +import ( + "context" + "encoding/json" + "github.com/stytchauth/stytch-go/v7/stytch" + "github.com/stytchauth/stytch-go/v7/stytch/b2b" + "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" +) + +type Client struct { + C *stytch.Client +} + +func (c *Client) LoginOrSignup( + ctx context.Context, + body *b2b.MagicLinksEmailLoginOrSignupParams, +) ( + *b2b.MagicLinksEmailLoginOrSignupResponse, error, +) { + path := "/b2b/magic_links/email/login_or_signup" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError("Oops, something seems to have gone wrong " + + "marshalling the /b2b/magic_links/email/login_or_signup request body") + } + } + + var retVal b2b.MagicLinksEmailLoginOrSignupResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} diff --git a/stytch/b2b/magiclink/magiclink.go b/stytch/b2b/magiclink/magiclink.go new file mode 100644 index 0000000..1d8cede --- /dev/null +++ b/stytch/b2b/magiclink/magiclink.go @@ -0,0 +1,38 @@ +package magiclink + +import ( + "context" + "encoding/json" + "github.com/stytchauth/stytch-go/v7/stytch/b2b" + "github.com/stytchauth/stytch-go/v7/stytch/b2b/magiclink/email" + + "github.com/stytchauth/stytch-go/v7/stytch" + "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" +) + +type Client struct { + C *stytch.Client + Email *email.Client +} + +func (c *Client) Authenticate( + ctx context.Context, + body *b2b.MagicLinksAuthenticateParams, +) (*b2b.MagicLinksAuthenticateResponse, error) { + path := "/b2b/magic_links/authenticate" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the /magic_links/authenticate request body") + } + } + + var retVal b2b.MagicLinksAuthenticateResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} diff --git a/stytch/b2b/organization.go b/stytch/b2b/organization.go new file mode 100644 index 0000000..b6e66e0 --- /dev/null +++ b/stytch/b2b/organization.go @@ -0,0 +1,46 @@ +package b2b + +type Organization struct { + OrganizationID string `json:"organization_id,omitempty"` + OrganizationName string `json:"organization_name,omitempty"` + OrganizationLogoURL string `json:"organization_logo_url,omitempty"` + OrganizationSlug string `json:"organization_slug,omitempty"` + TrustedMetadata map[string]interface{} `json:"trusted_metadata,omitempty"` + + SSODefaultConnectionID string `json:"sso_default_connection_id,omitempty"` + SSOJITProvisioning string `json:"sso_jit_provisioning,omitempty"` + SSOJITProvisioningAllowConnections []string `json:"sso_jit_provisioning_allowed_connections,omitempty"` + SSOActiveConnections []ActiveSSOConnection `json:"sso_active_connections,omitempty"` + + EmailAllowedDomains []string `json:"email_allowed_domains,omitempty"` + EmailJITProvisioning string `json:"email_jit_provisioning,omitempty"` + EmailInvites string `json:"email_invites,omitempty"` + + AuthMethods string `json:"auth_methods,omitempty"` + AllowedAuthMethods []string `json:"allowed_auth_methods,omitempty"` +} + +type Member struct { + OrganizationID string `json:"organization_id,omitempty"` + MemberID string `json:"member_id,omitempty"` + EmailAddress string `json:"email_address,omitempty"` + Status string `json:"status,omitempty"` + Name string `json:"name,omitempty"` + SSORegistration []SSORegistrations `json:"sso_registrations,omitempty"` + TrustedMetadata map[string]interface{} `json:"trusted_metadata,omitempty"` + UntrustedMetadata map[string]interface{} `json:"untrusted_metadata,omitempty"` + IsBreakglass bool `json:"is_breakglass,omitempty"` + MemberPasswordID string `json:"member_password_id,omitempty"` +} + +type ActiveSSOConnection struct { + ConnectionID string `json:"connection_id,omitempty"` + DisplayName string `json:"display_name,omitempty"` +} + +type SSORegistrations struct { + ConnectionID string `json:"connection_id,omitempty"` + ExternalID string `json:"external_id,omitempty"` + RegistrationID string `json:"registration_id,omitempty"` + SSOAttributes map[string]interface{} `json:"sso_attributes,omitempty"` +} diff --git a/stytch/b2b/session.go b/stytch/b2b/session.go new file mode 100644 index 0000000..e45fb2d --- /dev/null +++ b/stytch/b2b/session.go @@ -0,0 +1,4 @@ +package b2b + +type MemberSession struct { +} diff --git a/stytch/attributes.go b/stytch/b2c/attributes.go similarity index 99% rename from stytch/attributes.go rename to stytch/b2c/attributes.go index 6211a40..0846431 100644 --- a/stytch/attributes.go +++ b/stytch/b2c/attributes.go @@ -1,4 +1,4 @@ -package stytch +package b2c import "github.com/golang-jwt/jwt/v4" diff --git a/stytch/cryptowallet.go b/stytch/b2c/cryptowallet.go similarity index 99% rename from stytch/cryptowallet.go rename to stytch/b2c/cryptowallet.go index d0a0bbd..17ad61a 100644 --- a/stytch/cryptowallet.go +++ b/stytch/b2c/cryptowallet.go @@ -1,4 +1,4 @@ -package stytch +package b2c type CryptoWalletAuthenticateStartParams struct { CryptoWalletAddress string `json:"crypto_wallet_address,omitempty"` diff --git a/stytch/cryptowallet/cryptowallet.go b/stytch/b2c/cryptowallet/cryptowallet.go similarity index 81% rename from stytch/cryptowallet/cryptowallet.go rename to stytch/b2c/cryptowallet/cryptowallet.go index 3146724..9968dfe 100644 --- a/stytch/cryptowallet/cryptowallet.go +++ b/stytch/b2c/cryptowallet/cryptowallet.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch" "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" @@ -15,8 +16,8 @@ type Client struct { func (c *Client) AuthenticateStart( ctx context.Context, - body *stytch.CryptoWalletAuthenticateStartParams, -) (*stytch.CryptoWalletAuthenticateStartResponse, error) { + body *b2c.CryptoWalletAuthenticateStartParams, +) (*b2c.CryptoWalletAuthenticateStartResponse, error) { path := "/crypto_wallets/authenticate/start" var jsonBody []byte @@ -29,15 +30,15 @@ func (c *Client) AuthenticateStart( } } - var retVal stytch.CryptoWalletAuthenticateStartResponse + var retVal b2c.CryptoWalletAuthenticateStartResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } func (c *Client) Authenticate( ctx context.Context, - body *stytch.CryptoWalletAuthenticateParams, -) (*stytch.CryptoWalletAuthenticateResponse, error) { + body *b2c.CryptoWalletAuthenticateParams, +) (*b2c.CryptoWalletAuthenticateResponse, error) { path := "/crypto_wallets/authenticate" var jsonBody []byte @@ -50,7 +51,7 @@ func (c *Client) Authenticate( } } - var retVal stytch.CryptoWalletAuthenticateResponse + var retVal b2c.CryptoWalletAuthenticateResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } @@ -61,9 +62,9 @@ func (c *Client) Authenticate( // ExampleClient_AuthenticateWithClaims_struct for examples func (c *Client) AuthenticateWithClaims( ctx context.Context, - body *stytch.CryptoWalletAuthenticateParams, + body *b2c.CryptoWalletAuthenticateParams, claims interface{}, -) (*stytch.CryptoWalletAuthenticateResponse, error) { +) (*b2c.CryptoWalletAuthenticateResponse, error) { path := "/crypto_wallets/authenticate" var jsonBody []byte @@ -82,15 +83,15 @@ func (c *Client) AuthenticateWithClaims( } // First extract the Stytch data. - var retVal stytch.CryptoWalletAuthenticateResponse + var retVal b2c.CryptoWalletAuthenticateResponse if err := json.Unmarshal(b, &retVal); err != nil { return nil, fmt.Errorf("unmarshal CryptoWalletAuthenticateResponse: %w", err) } // Then extract the custom claims. Build a claims wrapper using the caller's `claims` value so // the unmarshal fills it. - wrapper := stytch.SessionWrapper{ - Session: stytch.ClaimsWrapper{ + wrapper := b2c.SessionWrapper{ + Session: b2c.ClaimsWrapper{ Claims: claims, }, } diff --git a/stytch/magiclink.go b/stytch/b2c/magiclink.go similarity index 99% rename from stytch/magiclink.go rename to stytch/b2c/magiclink.go index fdbeca0..5d7b27a 100644 --- a/stytch/magiclink.go +++ b/stytch/b2c/magiclink.go @@ -1,4 +1,4 @@ -package stytch +package b2c type MagicLinksCreateParams struct { UserID string `json:"user_id,omitempty"` diff --git a/stytch/magiclink/email/email.go b/stytch/b2c/magiclink/email/email.go similarity index 77% rename from stytch/magiclink/email/email.go rename to stytch/b2c/magiclink/email/email.go index 408da9c..8c36bde 100644 --- a/stytch/magiclink/email/email.go +++ b/stytch/b2c/magiclink/email/email.go @@ -3,6 +3,7 @@ package email import ( "context" "encoding/json" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch" "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" @@ -14,8 +15,8 @@ type Client struct { func (c *Client) Send( ctx context.Context, - body *stytch.MagicLinksEmailSendParams, -) (*stytch.MagicLinksEmailSendResponse, error) { + body *b2c.MagicLinksEmailSendParams, +) (*b2c.MagicLinksEmailSendResponse, error) { path := "/magic_links/email/send" var jsonBody []byte @@ -28,16 +29,16 @@ func (c *Client) Send( } } - var retVal stytch.MagicLinksEmailSendResponse + var retVal b2c.MagicLinksEmailSendResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } func (c *Client) LoginOrCreate( ctx context.Context, - body *stytch.MagicLinksEmailLoginOrCreateParams, + body *b2c.MagicLinksEmailLoginOrCreateParams, ) ( - *stytch.MagicLinksEmailLoginOrCreateResponse, error, + *b2c.MagicLinksEmailLoginOrCreateResponse, error, ) { path := "/magic_links/email/login_or_create" @@ -51,15 +52,15 @@ func (c *Client) LoginOrCreate( } } - var retVal stytch.MagicLinksEmailLoginOrCreateResponse + var retVal b2c.MagicLinksEmailLoginOrCreateResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } func (c *Client) Invite( ctx context.Context, - body *stytch.MagicLinksEmailInviteParams, -) (*stytch.MagicLinksEmailInviteResponse, error) { + body *b2c.MagicLinksEmailInviteParams, +) (*b2c.MagicLinksEmailInviteResponse, error) { path := "/magic_links/email/invite" var jsonBody []byte @@ -72,16 +73,16 @@ func (c *Client) Invite( } } - var retVal stytch.MagicLinksEmailInviteResponse + var retVal b2c.MagicLinksEmailInviteResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } func (c *Client) RevokeInvite( ctx context.Context, - body *stytch.MagicLinksEmailRevokeInviteParams, + body *b2c.MagicLinksEmailRevokeInviteParams, ) ( - *stytch.MagicLinksEmailRevokeInviteResponse, error, + *b2c.MagicLinksEmailRevokeInviteResponse, error, ) { path := "/magic_links/email/revoke_invite" @@ -95,7 +96,7 @@ func (c *Client) RevokeInvite( } } - var retVal stytch.MagicLinksEmailRevokeInviteResponse + var retVal b2c.MagicLinksEmailRevokeInviteResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } diff --git a/stytch/magiclink/magiclink.go b/stytch/b2c/magiclink/magiclink.go similarity index 81% rename from stytch/magiclink/magiclink.go rename to stytch/b2c/magiclink/magiclink.go index 5d9759e..8464993 100644 --- a/stytch/magiclink/magiclink.go +++ b/stytch/b2c/magiclink/magiclink.go @@ -4,9 +4,10 @@ import ( "context" "encoding/json" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/magiclink/email" "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/magiclink/email" "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" ) @@ -17,8 +18,8 @@ type Client struct { func (c *Client) Create( ctx context.Context, - body *stytch.MagicLinksCreateParams, -) (*stytch.MagicLinksCreateResponse, error) { + body *b2c.MagicLinksCreateParams, +) (*b2c.MagicLinksCreateResponse, error) { path := "/magic_links" var jsonBody []byte @@ -32,15 +33,15 @@ func (c *Client) Create( } } - var retVal stytch.MagicLinksCreateResponse + var retVal b2c.MagicLinksCreateResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } func (c *Client) Authenticate( ctx context.Context, - body *stytch.MagicLinksAuthenticateParams, -) (*stytch.MagicLinksAuthenticateResponse, error) { + body *b2c.MagicLinksAuthenticateParams, +) (*b2c.MagicLinksAuthenticateResponse, error) { path := "/magic_links/authenticate" var jsonBody []byte @@ -54,7 +55,7 @@ func (c *Client) Authenticate( } } - var retVal stytch.MagicLinksAuthenticateResponse + var retVal b2c.MagicLinksAuthenticateResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } @@ -65,9 +66,9 @@ func (c *Client) Authenticate( // ExampleClient_AuthenticateWithClaims_struct for examples func (c *Client) AuthenticateWithClaims( ctx context.Context, - body *stytch.MagicLinksAuthenticateParams, + body *b2c.MagicLinksAuthenticateParams, claims interface{}, -) (*stytch.MagicLinksAuthenticateResponse, error) { +) (*b2c.MagicLinksAuthenticateResponse, error) { path := "/magic_links/authenticate" var jsonBody []byte @@ -87,15 +88,15 @@ func (c *Client) AuthenticateWithClaims( } // First extract the Stytch data. - var retVal stytch.MagicLinksAuthenticateResponse + var retVal b2c.MagicLinksAuthenticateResponse if err := json.Unmarshal(b, &retVal); err != nil { return nil, fmt.Errorf("unmarshal MagicLinksAuthenticateResponse: %w", err) } // Then extract the custom claims. Build a claims wrapper using the caller's `claims` value so // the unmarshal fills it. - wrapper := stytch.SessionWrapper{ - Session: stytch.ClaimsWrapper{ + wrapper := b2c.SessionWrapper{ + Session: b2c.ClaimsWrapper{ Claims: claims, }, } diff --git a/stytch/oauth.go b/stytch/b2c/oauth.go similarity index 99% rename from stytch/oauth.go rename to stytch/b2c/oauth.go index 33bdfa0..99985cd 100644 --- a/stytch/oauth.go +++ b/stytch/b2c/oauth.go @@ -1,4 +1,4 @@ -package stytch +package b2c import "time" diff --git a/stytch/oauth/oauth.go b/stytch/b2c/oauth/oauth.go similarity index 82% rename from stytch/oauth/oauth.go rename to stytch/b2c/oauth/oauth.go index 6f6a2f3..cf8c003 100644 --- a/stytch/oauth/oauth.go +++ b/stytch/b2c/oauth/oauth.go @@ -4,9 +4,10 @@ import ( "context" "encoding/json" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/magiclink/email" "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/magiclink/email" "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" ) @@ -17,8 +18,8 @@ type Client struct { func (c *Client) Authenticate( ctx context.Context, - body *stytch.OAuthAuthenticateParams, -) (*stytch.OAuthAuthenticateResponse, error) { + body *b2c.OAuthAuthenticateParams, +) (*b2c.OAuthAuthenticateResponse, error) { path := "/oauth/authenticate" var jsonBody []byte @@ -32,7 +33,7 @@ func (c *Client) Authenticate( } } - var retVal stytch.OAuthAuthenticateResponse + var retVal b2c.OAuthAuthenticateResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } @@ -43,9 +44,9 @@ func (c *Client) Authenticate( // ExampleClient_AuthenticateWithClaims_struct for examples func (c *Client) AuthenticateWithClaims( ctx context.Context, - body *stytch.OAuthAuthenticateParams, + body *b2c.OAuthAuthenticateParams, claims interface{}, -) (*stytch.OAuthAuthenticateResponse, error) { +) (*b2c.OAuthAuthenticateResponse, error) { path := "/oauth/authenticate" var jsonBody []byte @@ -65,15 +66,15 @@ func (c *Client) AuthenticateWithClaims( } // First extract the Stytch data. - var retVal stytch.OAuthAuthenticateResponse + var retVal b2c.OAuthAuthenticateResponse if err := json.Unmarshal(b, &retVal); err != nil { return nil, fmt.Errorf("unmarshal OAuthAuthenticateResponse: %w", err) } // Then extract the custom claims. Build a claims wrapper using the caller's `claims` value so // the unmarshal fills it. - wrapper := stytch.SessionWrapper{ - Session: stytch.ClaimsWrapper{ + wrapper := b2c.SessionWrapper{ + Session: b2c.ClaimsWrapper{ Claims: claims, }, } @@ -86,8 +87,8 @@ func (c *Client) AuthenticateWithClaims( func (c *Client) Attach( ctx context.Context, - body *stytch.OAuthAttachParams, -) (*stytch.OAuthAttachResponse, error) { + body *b2c.OAuthAttachParams, +) (*b2c.OAuthAttachResponse, error) { path := "/oauth/attach" var jsonBody []byte @@ -101,7 +102,7 @@ func (c *Client) Attach( } } - var retVal stytch.OAuthAttachResponse + var retVal b2c.OAuthAttachResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } diff --git a/stytch/otp.go b/stytch/b2c/otp.go similarity index 99% rename from stytch/otp.go rename to stytch/b2c/otp.go index 30d29fa..f7cc991 100644 --- a/stytch/otp.go +++ b/stytch/b2c/otp.go @@ -1,4 +1,4 @@ -package stytch +package b2c type OTPsAuthenticateParams struct { MethodID string `json:"method_id"` diff --git a/stytch/otp/email/email.go b/stytch/b2c/otp/email/email.go similarity index 78% rename from stytch/otp/email/email.go rename to stytch/b2c/otp/email/email.go index e813ad3..50beebe 100644 --- a/stytch/otp/email/email.go +++ b/stytch/b2c/otp/email/email.go @@ -3,6 +3,7 @@ package email import ( "context" "encoding/json" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch" "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" @@ -14,8 +15,8 @@ type Client struct { func (c *Client) Send( ctx context.Context, - body *stytch.OTPsEmailSendParams, -) (*stytch.OTPsEmailSendResponse, error) { + body *b2c.OTPsEmailSendParams, +) (*b2c.OTPsEmailSendResponse, error) { path := "/otps/email/send" var jsonBody []byte @@ -28,15 +29,15 @@ func (c *Client) Send( } } - var retVal stytch.OTPsEmailSendResponse + var retVal b2c.OTPsEmailSendResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } func (c *Client) LoginOrCreate( ctx context.Context, - body *stytch.OTPsEmailLoginOrCreateParams, -) (*stytch.OTPsEmailLoginOrCreateResponse, error) { + body *b2c.OTPsEmailLoginOrCreateParams, +) (*b2c.OTPsEmailLoginOrCreateResponse, error) { path := "/otps/email/login_or_create" var jsonBody []byte @@ -49,7 +50,7 @@ func (c *Client) LoginOrCreate( } } - var retVal stytch.OTPsEmailLoginOrCreateResponse + var retVal b2c.OTPsEmailLoginOrCreateResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } diff --git a/stytch/otp/otp.go b/stytch/b2c/otp/otp.go similarity index 79% rename from stytch/otp/otp.go rename to stytch/b2c/otp/otp.go index a62cfbe..4d75d79 100644 --- a/stytch/otp/otp.go +++ b/stytch/b2c/otp/otp.go @@ -4,11 +4,12 @@ import ( "context" "encoding/json" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/otp/email" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/otp/sms" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/otp/whatsapp" "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/otp/email" - "github.com/stytchauth/stytch-go/v7/stytch/otp/sms" - "github.com/stytchauth/stytch-go/v7/stytch/otp/whatsapp" "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" ) @@ -21,8 +22,8 @@ type Client struct { func (c *Client) Authenticate( ctx context.Context, - body *stytch.OTPsAuthenticateParams, -) (*stytch.OTPsAuthenticateResponse, error) { + body *b2c.OTPsAuthenticateParams, +) (*b2c.OTPsAuthenticateResponse, error) { path := "/otps/authenticate" var jsonBody []byte @@ -35,7 +36,7 @@ func (c *Client) Authenticate( } } - var retVal stytch.OTPsAuthenticateResponse + var retVal b2c.OTPsAuthenticateResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } @@ -46,9 +47,9 @@ func (c *Client) Authenticate( // ExampleClient_AuthenticateWithClaims_struct for examples func (c *Client) AuthenticateWithClaims( ctx context.Context, - body *stytch.OTPsAuthenticateParams, + body *b2c.OTPsAuthenticateParams, claims interface{}, -) (*stytch.OTPsAuthenticateResponse, error) { +) (*b2c.OTPsAuthenticateResponse, error) { path := "/otps/authenticate" var jsonBody []byte @@ -67,15 +68,15 @@ func (c *Client) AuthenticateWithClaims( } // First extract the Stytch data. - var retVal stytch.OTPsAuthenticateResponse + var retVal b2c.OTPsAuthenticateResponse if err := json.Unmarshal(b, &retVal); err != nil { return nil, fmt.Errorf("unmarshal OTPsAuthenticateResponse: %w", err) } // Then extract the custom claims. Build a claims wrapper using the caller's `claims` value so // the unmarshal fills it. - wrapper := stytch.SessionWrapper{ - Session: stytch.ClaimsWrapper{ + wrapper := b2c.SessionWrapper{ + Session: b2c.ClaimsWrapper{ Claims: claims, }, } diff --git a/stytch/otp/sms/sms.go b/stytch/b2c/otp/sms/sms.go similarity index 79% rename from stytch/otp/sms/sms.go rename to stytch/b2c/otp/sms/sms.go index 4f73593..ce60d8c 100644 --- a/stytch/otp/sms/sms.go +++ b/stytch/b2c/otp/sms/sms.go @@ -3,6 +3,7 @@ package sms import ( "context" "encoding/json" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch" "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" @@ -14,8 +15,8 @@ type Client struct { func (c *Client) Send( ctx context.Context, - body *stytch.OTPsSMSSendParams, -) (*stytch.OTPsSMSSendResponse, error) { + body *b2c.OTPsSMSSendParams, +) (*b2c.OTPsSMSSendResponse, error) { path := "/otps/sms/send" var jsonBody []byte @@ -28,15 +29,15 @@ func (c *Client) Send( } } - var retVal stytch.OTPsSMSSendResponse + var retVal b2c.OTPsSMSSendResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } func (c *Client) LoginOrCreate( ctx context.Context, - body *stytch.OTPsSMSLoginOrCreateParams, -) (*stytch.OTPsSMSLoginOrCreateResponse, error) { + body *b2c.OTPsSMSLoginOrCreateParams, +) (*b2c.OTPsSMSLoginOrCreateResponse, error) { path := "/otps/sms/login_or_create" var jsonBody []byte @@ -49,7 +50,7 @@ func (c *Client) LoginOrCreate( } } - var retVal stytch.OTPsSMSLoginOrCreateResponse + var retVal b2c.OTPsSMSLoginOrCreateResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } diff --git a/stytch/otp/whatsapp/whatsapp.go b/stytch/b2c/otp/whatsapp/whatsapp.go similarity index 77% rename from stytch/otp/whatsapp/whatsapp.go rename to stytch/b2c/otp/whatsapp/whatsapp.go index c3c6785..22e5e4e 100644 --- a/stytch/otp/whatsapp/whatsapp.go +++ b/stytch/b2c/otp/whatsapp/whatsapp.go @@ -3,6 +3,7 @@ package whatsapp import ( "context" "encoding/json" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch" "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" @@ -14,8 +15,8 @@ type Client struct { func (c *Client) Send( ctx context.Context, - body *stytch.OTPsWhatsAppSendParams, -) (*stytch.OTPsWhatsAppSendResponse, error) { + body *b2c.OTPsWhatsAppSendParams, +) (*b2c.OTPsWhatsAppSendResponse, error) { path := "/otps/whatsapp/send" var jsonBody []byte @@ -28,15 +29,15 @@ func (c *Client) Send( } } - var retVal stytch.OTPsWhatsAppSendResponse + var retVal b2c.OTPsWhatsAppSendResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } func (c *Client) LoginOrCreate( ctx context.Context, - body *stytch.OTPsWhatsAppLoginOrCreateParams, -) (*stytch.OTPsWhatsAppLoginOrCreateResponse, error) { + body *b2c.OTPsWhatsAppLoginOrCreateParams, +) (*b2c.OTPsWhatsAppLoginOrCreateResponse, error) { path := "/otps/whatsapp/login_or_create" var jsonBody []byte @@ -49,7 +50,7 @@ func (c *Client) LoginOrCreate( } } - var retVal stytch.OTPsWhatsAppLoginOrCreateResponse + var retVal b2c.OTPsWhatsAppLoginOrCreateResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } diff --git a/stytch/password.go b/stytch/b2c/password.go similarity index 99% rename from stytch/password.go rename to stytch/b2c/password.go index 39c1606..3c28f5c 100644 --- a/stytch/password.go +++ b/stytch/b2c/password.go @@ -1,4 +1,4 @@ -package stytch +package b2c type PasswordsCreateParams struct { Email string `json:"email"` diff --git a/stytch/password/email/email.go b/stytch/b2c/password/email/email.go similarity index 82% rename from stytch/password/email/email.go rename to stytch/b2c/password/email/email.go index 6806070..473c753 100644 --- a/stytch/password/email/email.go +++ b/stytch/b2c/password/email/email.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch" "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" @@ -15,8 +16,8 @@ type Client struct { func (c *Client) ResetStart( ctx context.Context, - body *stytch.PasswordEmailResetStartParams, -) (*stytch.PasswordEmailResetStartResponse, error) { + body *b2c.PasswordEmailResetStartParams, +) (*b2c.PasswordEmailResetStartResponse, error) { path := "/passwords/email/reset/start" var jsonBody []byte @@ -30,15 +31,15 @@ func (c *Client) ResetStart( } } - var retVal stytch.PasswordEmailResetStartResponse + var retVal b2c.PasswordEmailResetStartResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } func (c *Client) Reset( ctx context.Context, - body *stytch.PasswordEmailResetParams, -) (*stytch.PasswordEmailResetResponse, error) { + body *b2c.PasswordEmailResetParams, +) (*b2c.PasswordEmailResetResponse, error) { path := "/passwords/email/reset" var jsonBody []byte @@ -52,7 +53,7 @@ func (c *Client) Reset( } } - var retVal stytch.PasswordEmailResetResponse + var retVal b2c.PasswordEmailResetResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } @@ -63,9 +64,9 @@ func (c *Client) Reset( // ExampleClient_AuthenticateWithClaims_struct for examples func (c *Client) ResetWithClaims( ctx context.Context, - body *stytch.PasswordEmailResetParams, + body *b2c.PasswordEmailResetParams, claims interface{}, -) (*stytch.PasswordEmailResetResponse, error) { +) (*b2c.PasswordEmailResetResponse, error) { path := "/passwords/email/reset" var jsonBody []byte @@ -85,15 +86,15 @@ func (c *Client) ResetWithClaims( } // First extract the Stytch data. - var retVal stytch.PasswordEmailResetResponse + var retVal b2c.PasswordEmailResetResponse if err := json.Unmarshal(b, &retVal); err != nil { return nil, fmt.Errorf("unmarshal PasswordEmailResetResponse: %w", err) } // Then extract the custom claims. Build a claims wrapper using the caller's `claims` value so // the unmarshal fills it. - wrapper := stytch.SessionWrapper{ - Session: stytch.ClaimsWrapper{ + wrapper := b2c.SessionWrapper{ + Session: b2c.ClaimsWrapper{ Claims: claims, }, } diff --git a/stytch/password/existingpassword/existingpassword.go b/stytch/b2c/password/existingpassword/existingpassword.go similarity index 82% rename from stytch/password/existingpassword/existingpassword.go rename to stytch/b2c/password/existingpassword/existingpassword.go index 7e9f358..c52829e 100644 --- a/stytch/password/existingpassword/existingpassword.go +++ b/stytch/b2c/password/existingpassword/existingpassword.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch" "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" @@ -15,8 +16,8 @@ type Client struct { func (c *Client) Reset( ctx context.Context, - body *stytch.PasswordExistingPasswordResetParams, -) (*stytch.PasswordExistingPasswordResetResponse, error) { + body *b2c.PasswordExistingPasswordResetParams, +) (*b2c.PasswordExistingPasswordResetResponse, error) { path := "/passwords/existing_password/reset" var jsonBody []byte @@ -30,7 +31,7 @@ func (c *Client) Reset( } } - var retVal stytch.PasswordExistingPasswordResetResponse + var retVal b2c.PasswordExistingPasswordResetResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } @@ -41,9 +42,9 @@ func (c *Client) Reset( // ExampleClient_AuthenticateWithClaims_struct for examples func (c *Client) ResetWithClaims( ctx context.Context, - body *stytch.PasswordExistingPasswordResetParams, + body *b2c.PasswordExistingPasswordResetParams, claims interface{}, -) (*stytch.PasswordExistingPasswordResetResponse, error) { +) (*b2c.PasswordExistingPasswordResetResponse, error) { path := "/passwords/existing_password/reset" var jsonBody []byte @@ -63,15 +64,15 @@ func (c *Client) ResetWithClaims( } // First extract the Stytch data. - var retVal stytch.PasswordExistingPasswordResetResponse + var retVal b2c.PasswordExistingPasswordResetResponse if err := json.Unmarshal(b, &retVal); err != nil { return nil, fmt.Errorf("unmarshal PasswordExistingPasswordResetResponse: %w", err) } // Then extract the custom claims. Build a claims wrapper using the caller's `claims` value so // the unmarshal fills it. - wrapper := stytch.SessionWrapper{ - Session: stytch.ClaimsWrapper{ + wrapper := b2c.SessionWrapper{ + Session: b2c.ClaimsWrapper{ Claims: claims, }, } diff --git a/stytch/password/password.go b/stytch/b2c/password/password.go similarity index 80% rename from stytch/password/password.go rename to stytch/b2c/password/password.go index 078029c..efbce70 100644 --- a/stytch/password/password.go +++ b/stytch/b2c/password/password.go @@ -4,11 +4,12 @@ import ( "context" "encoding/json" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/password/email" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/password/existingpassword" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/password/session" "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/password/email" - "github.com/stytchauth/stytch-go/v7/stytch/password/existingpassword" - "github.com/stytchauth/stytch-go/v7/stytch/password/session" "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" ) @@ -21,8 +22,8 @@ type Client struct { func (c *Client) Create( ctx context.Context, - body *stytch.PasswordsCreateParams, -) (*stytch.PasswordsCreateResponse, error) { + body *b2c.PasswordsCreateParams, +) (*b2c.PasswordsCreateResponse, error) { path := "/passwords" var jsonBody []byte @@ -36,7 +37,7 @@ func (c *Client) Create( } } - var retVal stytch.PasswordsCreateResponse + var retVal b2c.PasswordsCreateResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } @@ -47,9 +48,9 @@ func (c *Client) Create( // ExampleClient_AuthenticateWithClaims_struct for examples func (c *Client) CreateWithClaims( ctx context.Context, - body *stytch.PasswordsCreateParams, + body *b2c.PasswordsCreateParams, claims interface{}, -) (*stytch.PasswordsCreateResponse, error) { +) (*b2c.PasswordsCreateResponse, error) { path := "/passwords" var jsonBody []byte @@ -69,15 +70,15 @@ func (c *Client) CreateWithClaims( } // First extract the Stytch data. - var retVal stytch.PasswordsCreateResponse + var retVal b2c.PasswordsCreateResponse if err := json.Unmarshal(b, &retVal); err != nil { return nil, fmt.Errorf("unmarshal PasswordsCreateResponse: %w", err) } // Then extract the custom claims. Build a claims wrapper using the caller's `claims` value so // the unmarshal fills it. - wrapper := stytch.SessionWrapper{ - Session: stytch.ClaimsWrapper{ + wrapper := b2c.SessionWrapper{ + Session: b2c.ClaimsWrapper{ Claims: claims, }, } @@ -90,8 +91,8 @@ func (c *Client) CreateWithClaims( func (c *Client) Authenticate( ctx context.Context, - body *stytch.PasswordsAuthenticateParams, -) (*stytch.PasswordsAuthenticateResponse, error) { + body *b2c.PasswordsAuthenticateParams, +) (*b2c.PasswordsAuthenticateResponse, error) { path := "/passwords/authenticate" var jsonBody []byte @@ -105,7 +106,7 @@ func (c *Client) Authenticate( } } - var retVal stytch.PasswordsAuthenticateResponse + var retVal b2c.PasswordsAuthenticateResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } @@ -116,9 +117,9 @@ func (c *Client) Authenticate( // ExampleClient_AuthenticateWithClaims_struct for examples func (c *Client) AuthenticateWithClaims( ctx context.Context, - body *stytch.PasswordsAuthenticateParams, + body *b2c.PasswordsAuthenticateParams, claims interface{}, -) (*stytch.PasswordsAuthenticateResponse, error) { +) (*b2c.PasswordsAuthenticateResponse, error) { path := "/passwords/authenticate" var jsonBody []byte @@ -138,15 +139,15 @@ func (c *Client) AuthenticateWithClaims( } // First extract the Stytch data. - var retVal stytch.PasswordsAuthenticateResponse + var retVal b2c.PasswordsAuthenticateResponse if err := json.Unmarshal(b, &retVal); err != nil { return nil, fmt.Errorf("unmarshal PasswordsAuthenticateResponse: %w", err) } // Then extract the custom claims. Build a claims wrapper using the caller's `claims` value so // the unmarshal fills it. - wrapper := stytch.SessionWrapper{ - Session: stytch.ClaimsWrapper{ + wrapper := b2c.SessionWrapper{ + Session: b2c.ClaimsWrapper{ Claims: claims, }, } @@ -159,8 +160,8 @@ func (c *Client) AuthenticateWithClaims( func (c *Client) StrengthCheck( ctx context.Context, - body *stytch.PasswordsStrengthCheckParams, -) (*stytch.PasswordsStrengthCheckResponse, error) { + body *b2c.PasswordsStrengthCheckParams, +) (*b2c.PasswordsStrengthCheckResponse, error) { path := "/passwords/strength_check" var jsonBody []byte @@ -174,15 +175,15 @@ func (c *Client) StrengthCheck( } } - var retVal stytch.PasswordsStrengthCheckResponse + var retVal b2c.PasswordsStrengthCheckResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } func (c *Client) Migrate( ctx context.Context, - body *stytch.PasswordsMigrateParams, -) (*stytch.PasswordsMigrateResponse, error) { + body *b2c.PasswordsMigrateParams, +) (*b2c.PasswordsMigrateResponse, error) { path := "/passwords/migrate" var jsonBody []byte @@ -196,7 +197,7 @@ func (c *Client) Migrate( } } - var retVal stytch.PasswordsMigrateResponse + var retVal b2c.PasswordsMigrateResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } diff --git a/stytch/password/session/session.go b/stytch/b2c/password/session/session.go similarity index 78% rename from stytch/password/session/session.go rename to stytch/b2c/password/session/session.go index 8690518..6f457d5 100644 --- a/stytch/password/session/session.go +++ b/stytch/b2c/password/session/session.go @@ -3,6 +3,7 @@ package session import ( "context" "encoding/json" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch" "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" @@ -14,8 +15,8 @@ type Client struct { func (c *Client) Reset( ctx context.Context, - body *stytch.PasswordSessionResetParams, -) (*stytch.PasswordSessionResetResponse, error) { + body *b2c.PasswordSessionResetParams, +) (*b2c.PasswordSessionResetResponse, error) { path := "/passwords/session/reset" var jsonBody []byte @@ -29,7 +30,7 @@ func (c *Client) Reset( } } - var retVal stytch.PasswordSessionResetResponse + var retVal b2c.PasswordSessionResetResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } diff --git a/stytch/session.go b/stytch/b2c/session.go similarity index 99% rename from stytch/session.go rename to stytch/b2c/session.go index 5871df9..42499b4 100644 --- a/stytch/session.go +++ b/stytch/b2c/session.go @@ -1,4 +1,4 @@ -package stytch +package b2c import ( "strings" diff --git a/stytch/session/session.go b/stytch/b2c/session/session.go similarity index 81% rename from stytch/session/session.go rename to stytch/b2c/session/session.go index 84bac3a..5ab1144 100644 --- a/stytch/session/session.go +++ b/stytch/b2c/session/session.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "time" "github.com/MicahParks/keyfunc" @@ -22,24 +23,24 @@ type Client struct { func (c *Client) Get( ctx context.Context, - body *stytch.SessionsGetParams, -) (*stytch.SessionsGetResponse, error) { + body *b2c.SessionsGetParams, +) (*b2c.SessionsGetResponse, error) { queryParams := make(map[string]string) if body != nil { queryParams["user_id"] = body.UserID } - var retVal stytch.SessionsGetResponse + var retVal b2c.SessionsGetResponse err := c.C.NewRequest(ctx, "GET", "/sessions", queryParams, nil, &retVal) return &retVal, err } func (c *Client) GetJWKS( - ctx context.Context, body *stytch.SessionsGetJWKSParams, -) (*stytch.SessionsGetJWKSResponse, error) { + ctx context.Context, body *b2c.SessionsGetJWKSParams, +) (*b2c.SessionsGetJWKSResponse, error) { path := "/sessions/jwks/" + body.ProjectID - var retVal stytch.SessionsGetJWKSResponse + var retVal b2c.SessionsGetJWKSResponse err := c.C.NewRequest(ctx, "GET", path, nil, nil, &retVal) return &retVal, err } @@ -47,8 +48,8 @@ func (c *Client) GetJWKS( func (c *Client) AuthenticateJWT( ctx context.Context, maxTokenAge time.Duration, - body *stytch.SessionsAuthenticateParams, -) (*stytch.SessionsAuthenticateResponse, error) { + body *b2c.SessionsAuthenticateParams, +) (*b2c.SessionsAuthenticateResponse, error) { if body.SessionJWT == "" || maxTokenAge == time.Duration(0) { return c.Authenticate(ctx, body) } @@ -59,7 +60,7 @@ func (c *Client) AuthenticateJWT( return c.Authenticate(ctx, body) } - return &stytch.SessionsAuthenticateResponse{ + return &b2c.SessionsAuthenticateResponse{ Session: *session, }, nil } @@ -67,9 +68,9 @@ func (c *Client) AuthenticateJWT( func (c *Client) AuthenticateJWTWithClaims( ctx context.Context, maxTokenAge time.Duration, - body *stytch.SessionsAuthenticateParams, + body *b2c.SessionsAuthenticateParams, claims interface{}, -) (*stytch.SessionsAuthenticateResponse, error) { +) (*b2c.SessionsAuthenticateResponse, error) { if body.SessionJWT == "" || maxTokenAge == time.Duration(0) { return c.AuthenticateWithClaims(ctx, body, claims) } @@ -80,7 +81,7 @@ func (c *Client) AuthenticateJWTWithClaims( return c.Authenticate(ctx, body) } - return &stytch.SessionsAuthenticateResponse{ + return &b2c.SessionsAuthenticateResponse{ Session: *session, }, nil } @@ -88,8 +89,8 @@ func (c *Client) AuthenticateJWTWithClaims( func (c *Client) AuthenticateJWTLocal( token string, maxTokenAge time.Duration, -) (*stytch.Session, error) { - var claims stytch.Claims +) (*b2c.Session, error) { + var claims b2c.Claims _, err := jwt.ParseWithClaims(token, &claims, c.JWKS.Keyfunc) if err != nil { return nil, fmt.Errorf("failed to parse JWT: %w", err) @@ -108,8 +109,8 @@ func (c *Client) AuthenticateJWTLocal( return &session, nil } -func marshalJWTIntoSession(claims stytch.Claims) stytch.Session { - var authFactorPtrs []*stytch.AuthenticationFactor +func marshalJWTIntoSession(claims b2c.Claims) b2c.Session { + var authFactorPtrs []*b2c.AuthenticationFactor for _, factor := range claims.StytchSession.AuthenticationFactors { factor := factor authFactorPtrs = append(authFactorPtrs, &factor) @@ -121,7 +122,7 @@ func marshalJWTIntoSession(claims stytch.Claims) stytch.Session { expiresAt = claims.RegisteredClaims.ExpiresAt.Time.Format(time.RFC3339) } - return stytch.Session{ + return b2c.Session{ SessionID: claims.StytchSession.ID, UserID: claims.RegisteredClaims.Subject, StartedAt: claims.StytchSession.StartedAt, @@ -134,8 +135,8 @@ func marshalJWTIntoSession(claims stytch.Claims) stytch.Session { func (c *Client) Authenticate( ctx context.Context, - body *stytch.SessionsAuthenticateParams, -) (*stytch.SessionsAuthenticateResponse, error) { + body *b2c.SessionsAuthenticateParams, +) (*b2c.SessionsAuthenticateResponse, error) { path := "/sessions/authenticate" var jsonBody []byte @@ -148,7 +149,7 @@ func (c *Client) Authenticate( } } - var retVal stytch.SessionsAuthenticateResponse + var retVal b2c.SessionsAuthenticateResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } @@ -159,9 +160,9 @@ func (c *Client) Authenticate( // ExampleClient_AuthenticateWithClaims_struct for examples func (c *Client) AuthenticateWithClaims( ctx context.Context, - body *stytch.SessionsAuthenticateParams, + body *b2c.SessionsAuthenticateParams, claims interface{}, -) (*stytch.SessionsAuthenticateResponse, error) { +) (*b2c.SessionsAuthenticateResponse, error) { path := "/sessions/authenticate" var jsonBody []byte @@ -180,15 +181,15 @@ func (c *Client) AuthenticateWithClaims( } // First extract the Stytch data. - var retVal stytch.SessionsAuthenticateResponse + var retVal b2c.SessionsAuthenticateResponse if err := json.Unmarshal(b, &retVal); err != nil { return nil, fmt.Errorf("unmarshal SessionsAuthenticateResponse: %w", err) } // Then extract the custom claims. Build a claims wrapper using the caller's `claims` value so // the unmarshal fills it. - wrapper := stytch.SessionWrapper{ - Session: stytch.ClaimsWrapper{ + wrapper := b2c.SessionWrapper{ + Session: b2c.ClaimsWrapper{ Claims: claims, }, } @@ -201,8 +202,8 @@ func (c *Client) AuthenticateWithClaims( func (c *Client) Revoke( ctx context.Context, - body *stytch.SessionsRevokeParams, -) (*stytch.SessionsRevokeResponse, error) { + body *b2c.SessionsRevokeParams, +) (*b2c.SessionsRevokeResponse, error) { path := "/sessions/revoke" var jsonBody []byte @@ -215,7 +216,7 @@ func (c *Client) Revoke( } } - var retVal stytch.SessionsRevokeResponse + var retVal b2c.SessionsRevokeResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } diff --git a/stytch/session/session_test.go b/stytch/b2c/session/session_test.go similarity index 93% rename from stytch/session/session_test.go rename to stytch/b2c/session/session_test.go index 00d5730..cd0a11e 100644 --- a/stytch/session/session_test.go +++ b/stytch/b2c/session/session_test.go @@ -5,6 +5,9 @@ import ( "crypto/rand" "crypto/rsa" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/session" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/stytchapi" "net/http" "net/http/httptest" "strings" @@ -17,8 +20,6 @@ import ( "github.com/stretchr/testify/require" "github.com/stytchauth/stytch-go/v7/stytch" "github.com/stytchauth/stytch-go/v7/stytch/config" - "github.com/stytchauth/stytch-go/v7/stytch/session" - "github.com/stytchauth/stytch-go/v7/stytch/stytchapi" ) func TestAuthenticateJWTLocal(t *testing.T) { @@ -79,22 +80,22 @@ func TestAuthenticateJWTLocal(t *testing.T) { session, err := sessions.AuthenticateJWTLocal(token, 3*time.Minute) require.NoError(t, err) - expected := &stytch.Session{ + expected := &b2c.Session{ SessionID: "session-live-e26a0ccb-0dc0-4edb-a4bb-e70210f43555", UserID: "user-live-fde03dd1-fff7-4b3c-9b31-ead3fbc224de", StartedAt: iat.Format(time.RFC3339), LastAccessedAt: iat.Format(time.RFC3339), ExpiresAt: exp.Format(time.RFC3339), - Attributes: stytch.Attributes{ + Attributes: b2c.Attributes{ IPAddress: "", UserAgent: "", }, - AuthenticationFactors: []*stytch.AuthenticationFactor{ + AuthenticationFactors: []*b2c.AuthenticationFactor{ { Type: "magic_link", DeliveryMethod: "email", LastAuthenticatedAt: iat.Format(time.RFC3339), - EmailFactor: stytch.EmailFactor{ + EmailFactor: b2c.EmailFactor{ EmailAddress: "sandbox@stytch.com", EmailID: "email-live-cca9d7d0-11b6-4167-9385-d7e0c9a77418", }, @@ -115,22 +116,22 @@ func TestAuthenticateJWTLocal(t *testing.T) { session, err := sessions.AuthenticateJWTLocal(token, 3*time.Minute) require.NoError(t, err) - expected := &stytch.Session{ + expected := &b2c.Session{ SessionID: "session-live-e26a0ccb-0dc0-4edb-a4bb-e70210f43555", UserID: "user-live-fde03dd1-fff7-4b3c-9b31-ead3fbc224de", StartedAt: iat.Format(time.RFC3339), LastAccessedAt: iat.Format(time.RFC3339), ExpiresAt: iat.Add(5 * time.Minute).Format(time.RFC3339), - Attributes: stytch.Attributes{ + Attributes: b2c.Attributes{ IPAddress: "", UserAgent: "", }, - AuthenticationFactors: []*stytch.AuthenticationFactor{ + AuthenticationFactors: []*b2c.AuthenticationFactor{ { Type: "magic_link", DeliveryMethod: "email", LastAuthenticatedAt: iat.Format(time.RFC3339), - EmailFactor: stytch.EmailFactor{ + EmailFactor: b2c.EmailFactor{ EmailAddress: "sandbox@stytch.com", EmailID: "email-live-cca9d7d0-11b6-4167-9385-d7e0c9a77418", }, @@ -186,7 +187,7 @@ func TestAuthenticateWithClaims(t *testing.T) { ) require.NoError(t, err) - req := &stytch.SessionsAuthenticateParams{ + req := &b2c.SessionsAuthenticateParams{ SessionToken: "fake session token", } @@ -286,7 +287,7 @@ func ExampleClient_AuthenticateWithClaims_map() { var mapClaims map[string]map[string]int32 _, _ = client.Sessions.AuthenticateWithClaims( context.Background(), - &stytch.SessionsAuthenticateParams{ + &b2c.SessionsAuthenticateParams{ SessionToken: "fake session token", }, &mapClaims, @@ -357,7 +358,7 @@ func ExampleClient_AuthenticateWithClaims_struct() { var structClaims StructClaims _, _ = client.Sessions.AuthenticateWithClaims( context.Background(), - &stytch.SessionsAuthenticateParams{ + &b2c.SessionsAuthenticateParams{ SessionToken: "fake session token", }, &structClaims, @@ -389,20 +390,20 @@ func signJWT(t *testing.T, keyID string, key *rsa.PrivateKey, claims jwt.Claims) return signed } -func sandboxClaims(t *testing.T, iat, exp time.Time) stytch.Claims { - return stytch.Claims{ - StytchSession: stytch.SessionClaim{ +func sandboxClaims(t *testing.T, iat, exp time.Time) b2c.Claims { + return b2c.Claims{ + StytchSession: b2c.SessionClaim{ ID: "session-live-e26a0ccb-0dc0-4edb-a4bb-e70210f43555", StartedAt: iat.Format(time.RFC3339), LastAccessedAt: iat.Format(time.RFC3339), ExpiresAt: exp.Format(time.RFC3339), - Attributes: stytch.Attributes{}, - AuthenticationFactors: []stytch.AuthenticationFactor{ + Attributes: b2c.Attributes{}, + AuthenticationFactors: []b2c.AuthenticationFactor{ { Type: "magic_link", DeliveryMethod: "email", LastAuthenticatedAt: iat.Format(time.RFC3339), - EmailFactor: stytch.EmailFactor{ + EmailFactor: b2c.EmailFactor{ EmailAddress: "sandbox@stytch.com", EmailID: "email-live-cca9d7d0-11b6-4167-9385-d7e0c9a77418", }, diff --git a/stytch/stytchapi/stytchapi.go b/stytch/b2c/stytchapi/stytchapi.go similarity index 74% rename from stytch/stytchapi/stytchapi.go rename to stytch/b2c/stytchapi/stytchapi.go index 245ee76..8c281d2 100644 --- a/stytch/stytchapi/stytchapi.go +++ b/stytch/b2c/stytchapi/stytchapi.go @@ -3,27 +3,27 @@ package stytchapi import ( "context" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/cryptowallet" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/magiclink" + mle "github.com/stytchauth/stytch-go/v7/stytch/b2c/magiclink/email" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/oauth" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/otp" + otpe "github.com/stytchauth/stytch-go/v7/stytch/b2c/otp/email" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/otp/sms" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/otp/whatsapp" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/password" + pe "github.com/stytchauth/stytch-go/v7/stytch/b2c/password/email" + pep "github.com/stytchauth/stytch-go/v7/stytch/b2c/password/existingpassword" + ps "github.com/stytchauth/stytch-go/v7/stytch/b2c/password/session" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/session" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/totp" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/user" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/webauthn" "time" "github.com/MicahParks/keyfunc" "github.com/stytchauth/stytch-go/v7/stytch" "github.com/stytchauth/stytch-go/v7/stytch/config" - "github.com/stytchauth/stytch-go/v7/stytch/cryptowallet" - "github.com/stytchauth/stytch-go/v7/stytch/magiclink" - mle "github.com/stytchauth/stytch-go/v7/stytch/magiclink/email" - "github.com/stytchauth/stytch-go/v7/stytch/oauth" - "github.com/stytchauth/stytch-go/v7/stytch/otp" - otpe "github.com/stytchauth/stytch-go/v7/stytch/otp/email" - "github.com/stytchauth/stytch-go/v7/stytch/otp/sms" - "github.com/stytchauth/stytch-go/v7/stytch/otp/whatsapp" - "github.com/stytchauth/stytch-go/v7/stytch/password" - pe "github.com/stytchauth/stytch-go/v7/stytch/password/email" - pep "github.com/stytchauth/stytch-go/v7/stytch/password/existingpassword" - ps "github.com/stytchauth/stytch-go/v7/stytch/password/session" - "github.com/stytchauth/stytch-go/v7/stytch/session" - "github.com/stytchauth/stytch-go/v7/stytch/totp" - "github.com/stytchauth/stytch-go/v7/stytch/user" - "github.com/stytchauth/stytch-go/v7/stytch/webauthn" ) type Logger interface { diff --git a/stytch/stytchapi/stytchapi_test.go b/stytch/b2c/stytchapi/stytchapi_test.go similarity index 91% rename from stytch/stytchapi/stytchapi_test.go rename to stytch/b2c/stytchapi/stytchapi_test.go index 8182c50..6a5d0c8 100644 --- a/stytch/stytchapi/stytchapi_test.go +++ b/stytch/b2c/stytchapi/stytchapi_test.go @@ -2,6 +2,8 @@ package stytchapi_test import ( "context" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/stytchapi" "net/http" "net/http/httptest" "strings" @@ -10,7 +12,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stytchauth/stytch-go/v7/stytch" "github.com/stytchauth/stytch-go/v7/stytch/config" - "github.com/stytchauth/stytch-go/v7/stytch/stytchapi" ) func TestNewClient(t *testing.T) { @@ -59,7 +60,7 @@ func TestNewClient(t *testing.T) { _, err = client.MagicLinks.Authenticate( context.Background(), - &stytch.MagicLinksAuthenticateParams{ + &b2c.MagicLinksAuthenticateParams{ Token: "fake-token", }, ) diff --git a/stytch/totp.go b/stytch/b2c/totp.go similarity index 99% rename from stytch/totp.go rename to stytch/b2c/totp.go index 954052e..e5add0f 100644 --- a/stytch/totp.go +++ b/stytch/b2c/totp.go @@ -1,4 +1,4 @@ -package stytch +package b2c type TOTP struct { TOTPID string `json:"totp_id,omitempty"` diff --git a/stytch/totp/totp.go b/stytch/b2c/totp/totp.go similarity index 81% rename from stytch/totp/totp.go rename to stytch/b2c/totp/totp.go index 59ac508..3a77c3d 100644 --- a/stytch/totp/totp.go +++ b/stytch/b2c/totp/totp.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch" "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" @@ -13,8 +14,8 @@ type Client struct { C *stytch.Client } -func (c *Client) Create(ctx context.Context, body *stytch.TOTPsCreateParams) ( - *stytch.TOTPsCreateResponse, error, +func (c *Client) Create(ctx context.Context, body *b2c.TOTPsCreateParams) ( + *b2c.TOTPsCreateResponse, error, ) { path := "/totps" @@ -29,13 +30,13 @@ func (c *Client) Create(ctx context.Context, body *stytch.TOTPsCreateParams) ( } } - var retVal stytch.TOTPsCreateResponse + var retVal b2c.TOTPsCreateResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } -func (c *Client) Authenticate(ctx context.Context, body *stytch.TOTPsAuthenticateParams) ( - *stytch.TOTPsAuthenticateResponse, error, +func (c *Client) Authenticate(ctx context.Context, body *b2c.TOTPsAuthenticateParams) ( + *b2c.TOTPsAuthenticateResponse, error, ) { path := "/totps/authenticate" @@ -50,7 +51,7 @@ func (c *Client) Authenticate(ctx context.Context, body *stytch.TOTPsAuthenticat } } - var retVal stytch.TOTPsAuthenticateResponse + var retVal b2c.TOTPsAuthenticateResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } @@ -61,9 +62,9 @@ func (c *Client) Authenticate(ctx context.Context, body *stytch.TOTPsAuthenticat // ExampleClient_AuthenticateWithClaims_struct for examples func (c *Client) AuthenticateWithClaims( ctx context.Context, - body *stytch.TOTPsAuthenticateParams, + body *b2c.TOTPsAuthenticateParams, claims interface{}, -) (*stytch.TOTPsAuthenticateResponse, error) { +) (*b2c.TOTPsAuthenticateResponse, error) { path := "/totps/authenticate" var jsonBody []byte @@ -83,14 +84,14 @@ func (c *Client) AuthenticateWithClaims( } // First extract the Stytch data. - var retVal stytch.TOTPsAuthenticateResponse + var retVal b2c.TOTPsAuthenticateResponse if err := json.Unmarshal(b, &retVal); err != nil { return nil, fmt.Errorf("unmarshal TOTPsAuthenticateResponse: %w", err) } // Then extract the custom claims. Build a claims wrapper using the caller's `claims` value so // the unmarshal fills it. - wrapper := stytch.SessionWrapper{ + wrapper := b2c.SessionWrapper{ Session: struct { Claims interface{} `json:"custom_claims"` }{ @@ -104,8 +105,8 @@ func (c *Client) AuthenticateWithClaims( return &retVal, err } -func (c *Client) RecoveryCodes(ctx context.Context, body *stytch.TOTPsRecoveryCodesParams) ( - *stytch.TOTPsRecoveryCodesResponse, error, +func (c *Client) RecoveryCodes(ctx context.Context, body *b2c.TOTPsRecoveryCodesParams) ( + *b2c.TOTPsRecoveryCodesResponse, error, ) { path := "/totps/recovery_codes" @@ -120,13 +121,13 @@ func (c *Client) RecoveryCodes(ctx context.Context, body *stytch.TOTPsRecoveryCo } } - var retVal stytch.TOTPsRecoveryCodesResponse + var retVal b2c.TOTPsRecoveryCodesResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } -func (c *Client) Recover(ctx context.Context, body *stytch.TOTPsRecoverParams) ( - *stytch.TOTPsRecoverResponse, error, +func (c *Client) Recover(ctx context.Context, body *b2c.TOTPsRecoverParams) ( + *b2c.TOTPsRecoverResponse, error, ) { path := "/totps/recover" @@ -141,7 +142,7 @@ func (c *Client) Recover(ctx context.Context, body *stytch.TOTPsRecoverParams) ( } } - var retVal stytch.TOTPsRecoverResponse + var retVal b2c.TOTPsRecoverResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } @@ -152,9 +153,9 @@ func (c *Client) Recover(ctx context.Context, body *stytch.TOTPsRecoverParams) ( // ExampleClient_AuthenticateWithClaims_struct for examples func (c *Client) RecoverWithClaims( ctx context.Context, - body *stytch.TOTPsRecoverParams, + body *b2c.TOTPsRecoverParams, claims interface{}, -) (*stytch.TOTPsRecoverResponse, error) { +) (*b2c.TOTPsRecoverResponse, error) { path := "/totps/recover" var jsonBody []byte @@ -174,15 +175,15 @@ func (c *Client) RecoverWithClaims( } // First extract the Stytch data. - var retVal stytch.TOTPsRecoverResponse + var retVal b2c.TOTPsRecoverResponse if err := json.Unmarshal(b, &retVal); err != nil { return nil, fmt.Errorf("unmarshal TOTPsRecoverResponse: %w", err) } // Then extract the custom claims. Build a claims wrapper using the caller's `claims` value so // the unmarshal fills it. - wrapper := stytch.SessionWrapper{ - Session: stytch.ClaimsWrapper{ + wrapper := b2c.SessionWrapper{ + Session: b2c.ClaimsWrapper{ Claims: claims, }, } diff --git a/stytch/user.go b/stytch/b2c/user.go similarity index 99% rename from stytch/user.go rename to stytch/b2c/user.go index e56d036..7dd3b09 100644 --- a/stytch/user.go +++ b/stytch/b2c/user.go @@ -1,4 +1,4 @@ -package stytch +package b2c import ( "encoding/json" diff --git a/stytch/user/user.go b/stytch/b2c/user/user.go similarity index 74% rename from stytch/user/user.go rename to stytch/b2c/user/user.go index 32cdf45..df58019 100644 --- a/stytch/user/user.go +++ b/stytch/b2c/user/user.go @@ -3,6 +3,7 @@ package user import ( "context" "encoding/json" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "strconv" "github.com/stytchauth/stytch-go/v7/stytch" @@ -15,8 +16,8 @@ type Client struct { func (c *Client) Create( ctx context.Context, - body *stytch.UsersCreateParams, -) (*stytch.UsersCreateResponse, error) { + body *b2c.UsersCreateParams, +) (*b2c.UsersCreateResponse, error) { var jsonBody []byte var err error if body != nil { @@ -27,7 +28,7 @@ func (c *Client) Create( } } - var retVal stytch.UsersCreateResponse + var retVal b2c.UsersCreateResponse err = c.C.NewRequest(ctx, "POST", "/users", nil, jsonBody, &retVal) return &retVal, err } @@ -35,18 +36,18 @@ func (c *Client) Create( func (c *Client) Get( ctx context.Context, userID string, -) (*stytch.UsersGetResponse, error) { +) (*b2c.UsersGetResponse, error) { path := "/users/" + userID - var retVal stytch.UsersGetResponse + var retVal b2c.UsersGetResponse err := c.C.NewRequest(ctx, "GET", path, nil, nil, &retVal) return &retVal, err } func (c *Client) GetPending( ctx context.Context, - body *stytch.UsersGetPendingParams, -) (*stytch.UsersGetPendingResponse, error) { + body *b2c.UsersGetPendingParams, +) (*b2c.UsersGetPendingResponse, error) { var queryParams map[string]string if body != nil { limitString := "" @@ -60,15 +61,15 @@ func (c *Client) GetPending( } } - var retVal stytch.UsersGetPendingResponse + var retVal b2c.UsersGetPendingResponse err := c.C.NewRequest(ctx, "GET", "/users/pending", queryParams, nil, &retVal) return &retVal, err } func (c *Client) Search( ctx context.Context, - body *stytch.UsersSearchParams, -) (*stytch.UsersSearchResponse, error) { + body *b2c.UsersSearchParams, +) (*b2c.UsersSearchResponse, error) { var jsonBody []byte var err error if body != nil { @@ -79,7 +80,7 @@ func (c *Client) Search( } } - var retVal stytch.UsersSearchResponse + var retVal b2c.UsersSearchResponse err = c.C.NewRequest(ctx, "POST", "/users/search", nil, jsonBody, &retVal) return &retVal, err } @@ -95,7 +96,7 @@ const ( type UserSearchIterator struct { c *Client - body *stytch.UsersSearchParams + body *b2c.UsersSearchParams state iteratorState } @@ -103,7 +104,7 @@ func (i *UserSearchIterator) HasNext() bool { return i.state == iteratorStatePending || i.state == iteratorStateInProgress } -func (i *UserSearchIterator) Next(ctx context.Context) ([]stytch.User, error) { +func (i *UserSearchIterator) Next(ctx context.Context) ([]b2c.User, error) { res, err := i.c.Search(ctx, i.body) if err != nil { i.state = iteratorStateErrored @@ -118,7 +119,7 @@ func (i *UserSearchIterator) Next(ctx context.Context) ([]stytch.User, error) { return res.Results, nil } -func (c *Client) SearchAll(body *stytch.UsersSearchParams) *UserSearchIterator { +func (c *Client) SearchAll(body *b2c.UsersSearchParams) *UserSearchIterator { return &UserSearchIterator{ c: c, body: body, @@ -129,8 +130,8 @@ func (c *Client) SearchAll(body *stytch.UsersSearchParams) *UserSearchIterator { func (c *Client) Update( ctx context.Context, userID string, - body *stytch.UsersUpdateParams, -) (*stytch.UsersUpdateResponse, error) { + body *b2c.UsersUpdateParams, +) (*b2c.UsersUpdateResponse, error) { path := "/users/" + userID var jsonBody []byte @@ -143,7 +144,7 @@ func (c *Client) Update( } } - var retVal stytch.UsersUpdateResponse + var retVal b2c.UsersUpdateResponse err = c.C.NewRequest(ctx, "PUT", path, nil, jsonBody, &retVal) return &retVal, err } @@ -151,10 +152,10 @@ func (c *Client) Update( func (c *Client) Delete( ctx context.Context, userID string, -) (*stytch.UsersDeleteResponse, error) { +) (*b2c.UsersDeleteResponse, error) { path := "/users/" + userID - var retVal stytch.UsersDeleteResponse + var retVal b2c.UsersDeleteResponse err := c.C.NewRequest(ctx, "DELETE", path, nil, nil, &retVal) return &retVal, err } @@ -162,10 +163,10 @@ func (c *Client) Delete( func (c *Client) DeleteEmail( ctx context.Context, emailID string, -) (*stytch.UsersDeleteEmailResponse, error) { +) (*b2c.UsersDeleteEmailResponse, error) { path := "/users/emails/" + emailID - var retVal stytch.UsersDeleteEmailResponse + var retVal b2c.UsersDeleteEmailResponse err := c.C.NewRequest(ctx, "DELETE", path, nil, nil, &retVal) return &retVal, err } @@ -173,10 +174,10 @@ func (c *Client) DeleteEmail( func (c *Client) DeletePhoneNumber( ctx context.Context, phoneID string, -) (*stytch.UsersDeletePhoneNumberResponse, error) { +) (*b2c.UsersDeletePhoneNumberResponse, error) { path := "/users/phone_numbers/" + phoneID - var retVal stytch.UsersDeletePhoneNumberResponse + var retVal b2c.UsersDeletePhoneNumberResponse err := c.C.NewRequest(ctx, "DELETE", path, nil, nil, &retVal) return &retVal, err } @@ -184,10 +185,10 @@ func (c *Client) DeletePhoneNumber( func (c *Client) DeleteWebAuthnRegistration( ctx context.Context, webAuthnRegistration string, -) (*stytch.UsersDeleteWebAuthnRegistrationResponse, error) { +) (*b2c.UsersDeleteWebAuthnRegistrationResponse, error) { path := "/users/webauthn_registrations/" + webAuthnRegistration - var retVal stytch.UsersDeleteWebAuthnRegistrationResponse + var retVal b2c.UsersDeleteWebAuthnRegistrationResponse err := c.C.NewRequest(ctx, "DELETE", path, nil, nil, &retVal) return &retVal, err } @@ -195,10 +196,10 @@ func (c *Client) DeleteWebAuthnRegistration( func (c *Client) DeleteBiometricRegistration( ctx context.Context, biometricRegistrationID string, -) (*stytch.UsersDeleteBiometricRegistrationResponse, error) { +) (*b2c.UsersDeleteBiometricRegistrationResponse, error) { path := "/users/biometric_registrations/" + biometricRegistrationID - var retVal stytch.UsersDeleteBiometricRegistrationResponse + var retVal b2c.UsersDeleteBiometricRegistrationResponse err := c.C.NewRequest(ctx, "DELETE", path, nil, nil, &retVal) return &retVal, err } @@ -206,10 +207,10 @@ func (c *Client) DeleteBiometricRegistration( func (c *Client) DeleteTOTP( ctx context.Context, totpID string, -) (*stytch.UsersDeleteTOTPResponse, error) { +) (*b2c.UsersDeleteTOTPResponse, error) { path := "/users/totps/" + totpID - var retVal stytch.UsersDeleteTOTPResponse + var retVal b2c.UsersDeleteTOTPResponse err := c.C.NewRequest(ctx, "DELETE", path, nil, nil, &retVal) return &retVal, err } @@ -217,10 +218,10 @@ func (c *Client) DeleteTOTP( func (c *Client) DeleteCryptoWallet( ctx context.Context, cryptoWalletID string, -) (*stytch.UsersDeleteCryptoWalletResponse, error) { +) (*b2c.UsersDeleteCryptoWalletResponse, error) { path := "/users/crypto_wallets/" + cryptoWalletID - var retVal stytch.UsersDeleteCryptoWalletResponse + var retVal b2c.UsersDeleteCryptoWalletResponse err := c.C.NewRequest(ctx, "DELETE", path, nil, nil, &retVal) return &retVal, err } @@ -228,10 +229,10 @@ func (c *Client) DeleteCryptoWallet( func (c *Client) DeletePassword( ctx context.Context, passwordID string, -) (*stytch.UsersDeletePasswordResponse, error) { +) (*b2c.UsersDeletePasswordResponse, error) { path := "/users/passwords/" + passwordID - var retVal stytch.UsersDeletePasswordResponse + var retVal b2c.UsersDeletePasswordResponse err := c.C.NewRequest(ctx, "DELETE", path, nil, nil, &retVal) return &retVal, err } @@ -239,10 +240,10 @@ func (c *Client) DeletePassword( func (c *Client) DeleteOAuthUserRegistration( ctx context.Context, oauthUserRegistrationID string, -) (*stytch.UsersDeleteOAuthRegistrationResponse, error) { +) (*b2c.UsersDeleteOAuthRegistrationResponse, error) { path := "/users/oauth/" + oauthUserRegistrationID - var retVal stytch.UsersDeleteOAuthRegistrationResponse + var retVal b2c.UsersDeleteOAuthRegistrationResponse err := c.C.NewRequest(ctx, "DELETE", path, nil, nil, &retVal) return &retVal, err } diff --git a/stytch/webauthn.go b/stytch/b2c/webauthn.go similarity index 99% rename from stytch/webauthn.go rename to stytch/b2c/webauthn.go index 6010a0e..686f160 100644 --- a/stytch/webauthn.go +++ b/stytch/b2c/webauthn.go @@ -1,4 +1,4 @@ -package stytch +package b2c type WebAuthnRegisterStartParams struct { UserID string `json:"user_id,omitempty"` diff --git a/stytch/webauthn/webauthn.go b/stytch/b2c/webauthn/webauthn.go similarity index 80% rename from stytch/webauthn/webauthn.go rename to stytch/b2c/webauthn/webauthn.go index bb38a88..387fb1e 100644 --- a/stytch/webauthn/webauthn.go +++ b/stytch/b2c/webauthn/webauthn.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch" "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" @@ -15,8 +16,8 @@ type Client struct { func (c *Client) RegisterStart( ctx context.Context, - body *stytch.WebAuthnRegisterStartParams, -) (*stytch.WebAuthnRegisterStartResponse, error) { + body *b2c.WebAuthnRegisterStartParams, +) (*b2c.WebAuthnRegisterStartResponse, error) { path := "/webauthn/register/start" var jsonBody []byte @@ -29,15 +30,15 @@ func (c *Client) RegisterStart( } } - var retVal stytch.WebAuthnRegisterStartResponse + var retVal b2c.WebAuthnRegisterStartResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } func (c *Client) Register( ctx context.Context, - body *stytch.WebAuthnRegisterParams, -) (*stytch.WebAuthnRegisterResponse, error) { + body *b2c.WebAuthnRegisterParams, +) (*b2c.WebAuthnRegisterResponse, error) { path := "/webauthn/register" var jsonBody []byte @@ -50,15 +51,15 @@ func (c *Client) Register( } } - var retVal stytch.WebAuthnRegisterResponse + var retVal b2c.WebAuthnRegisterResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } func (c *Client) AuthenticateStart( ctx context.Context, - body *stytch.WebAuthnAuthenticateStartParams, -) (*stytch.WebAuthnAuthenticateStartResponse, error) { + body *b2c.WebAuthnAuthenticateStartParams, +) (*b2c.WebAuthnAuthenticateStartResponse, error) { path := "/webauthn/authenticate/start" var jsonBody []byte @@ -71,15 +72,15 @@ func (c *Client) AuthenticateStart( } } - var retVal stytch.WebAuthnAuthenticateStartResponse + var retVal b2c.WebAuthnAuthenticateStartResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } func (c *Client) Authenticate( ctx context.Context, - body *stytch.WebAuthnAuthenticateParams, -) (*stytch.WebAuthnAuthenticateResponse, error) { + body *b2c.WebAuthnAuthenticateParams, +) (*b2c.WebAuthnAuthenticateResponse, error) { path := "/webauthn/authenticate" var jsonBody []byte @@ -92,7 +93,7 @@ func (c *Client) Authenticate( } } - var retVal stytch.WebAuthnAuthenticateResponse + var retVal b2c.WebAuthnAuthenticateResponse err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } @@ -103,9 +104,9 @@ func (c *Client) Authenticate( // ExampleClient_AuthenticateWithClaims_struct for examples func (c *Client) AuthenticateWithClaims( ctx context.Context, - body *stytch.WebAuthnAuthenticateParams, + body *b2c.WebAuthnAuthenticateParams, claims interface{}, -) (*stytch.WebAuthnAuthenticateResponse, error) { +) (*b2c.WebAuthnAuthenticateResponse, error) { path := "/webauthn/authenticate" var jsonBody []byte @@ -124,15 +125,15 @@ func (c *Client) AuthenticateWithClaims( } // First extract the Stytch data. - var retVal stytch.WebAuthnAuthenticateResponse + var retVal b2c.WebAuthnAuthenticateResponse if err := json.Unmarshal(b, &retVal); err != nil { return nil, fmt.Errorf("unmarshal WebAuthnAuthenticateResponse: %w", err) } // Then extract the custom claims. Build a claims wrapper using the caller's `claims` value so // the unmarshal fills it. - wrapper := stytch.SessionWrapper{ - Session: stytch.ClaimsWrapper{ + wrapper := b2c.SessionWrapper{ + Session: b2c.ClaimsWrapper{ Claims: claims, }, } From 3d197a4e5cd87953c6c752a89fdc234733b249e5 Mon Sep 17 00:00:00 2001 From: alex-stytch Date: Tue, 25 Apr 2023 14:28:26 -0700 Subject: [PATCH 02/12] lint --- stytch/b2b/magiclink/email/email.go | 1 + stytch/b2b/magiclink/magiclink.go | 1 + stytch/b2b/session.go | 3 +-- stytch/b2c/cryptowallet/cryptowallet.go | 1 + stytch/b2c/magiclink/email/email.go | 1 + stytch/b2c/magiclink/magiclink.go | 1 + stytch/b2c/oauth/oauth.go | 1 + stytch/b2c/otp/email/email.go | 1 + stytch/b2c/otp/otp.go | 1 + stytch/b2c/otp/sms/sms.go | 1 + stytch/b2c/otp/whatsapp/whatsapp.go | 1 + stytch/b2c/password/email/email.go | 1 + stytch/b2c/password/existingpassword/existingpassword.go | 1 + stytch/b2c/password/password.go | 1 + stytch/b2c/password/session/session.go | 1 + stytch/b2c/session/session.go | 3 ++- stytch/b2c/session/session_test.go | 7 ++++--- stytch/b2c/stytchapi/stytchapi.go | 3 ++- stytch/b2c/stytchapi/stytchapi_test.go | 5 +++-- stytch/b2c/totp/totp.go | 1 + stytch/b2c/user/user.go | 3 ++- stytch/b2c/webauthn/webauthn.go | 1 + 22 files changed, 30 insertions(+), 10 deletions(-) diff --git a/stytch/b2b/magiclink/email/email.go b/stytch/b2b/magiclink/email/email.go index 69c438d..7813cfd 100644 --- a/stytch/b2b/magiclink/email/email.go +++ b/stytch/b2b/magiclink/email/email.go @@ -3,6 +3,7 @@ package email import ( "context" "encoding/json" + "github.com/stytchauth/stytch-go/v7/stytch" "github.com/stytchauth/stytch-go/v7/stytch/b2b" "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" diff --git a/stytch/b2b/magiclink/magiclink.go b/stytch/b2b/magiclink/magiclink.go index 1d8cede..41d589c 100644 --- a/stytch/b2b/magiclink/magiclink.go +++ b/stytch/b2b/magiclink/magiclink.go @@ -3,6 +3,7 @@ package magiclink import ( "context" "encoding/json" + "github.com/stytchauth/stytch-go/v7/stytch/b2b" "github.com/stytchauth/stytch-go/v7/stytch/b2b/magiclink/email" diff --git a/stytch/b2b/session.go b/stytch/b2b/session.go index e45fb2d..1206dd6 100644 --- a/stytch/b2b/session.go +++ b/stytch/b2b/session.go @@ -1,4 +1,3 @@ package b2b -type MemberSession struct { -} +type MemberSession struct{} diff --git a/stytch/b2c/cryptowallet/cryptowallet.go b/stytch/b2c/cryptowallet/cryptowallet.go index 9968dfe..5e66fab 100644 --- a/stytch/b2c/cryptowallet/cryptowallet.go +++ b/stytch/b2c/cryptowallet/cryptowallet.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch" diff --git a/stytch/b2c/magiclink/email/email.go b/stytch/b2c/magiclink/email/email.go index 8c36bde..a5cfea4 100644 --- a/stytch/b2c/magiclink/email/email.go +++ b/stytch/b2c/magiclink/email/email.go @@ -3,6 +3,7 @@ package email import ( "context" "encoding/json" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch" diff --git a/stytch/b2c/magiclink/magiclink.go b/stytch/b2c/magiclink/magiclink.go index 8464993..149dde6 100644 --- a/stytch/b2c/magiclink/magiclink.go +++ b/stytch/b2c/magiclink/magiclink.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch/b2c/magiclink/email" diff --git a/stytch/b2c/oauth/oauth.go b/stytch/b2c/oauth/oauth.go index cf8c003..391239d 100644 --- a/stytch/b2c/oauth/oauth.go +++ b/stytch/b2c/oauth/oauth.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch/b2c/magiclink/email" diff --git a/stytch/b2c/otp/email/email.go b/stytch/b2c/otp/email/email.go index 50beebe..95a67e1 100644 --- a/stytch/b2c/otp/email/email.go +++ b/stytch/b2c/otp/email/email.go @@ -3,6 +3,7 @@ package email import ( "context" "encoding/json" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch" diff --git a/stytch/b2c/otp/otp.go b/stytch/b2c/otp/otp.go index 4d75d79..ecbb3bf 100644 --- a/stytch/b2c/otp/otp.go +++ b/stytch/b2c/otp/otp.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch/b2c/otp/email" "github.com/stytchauth/stytch-go/v7/stytch/b2c/otp/sms" diff --git a/stytch/b2c/otp/sms/sms.go b/stytch/b2c/otp/sms/sms.go index ce60d8c..37b1f3c 100644 --- a/stytch/b2c/otp/sms/sms.go +++ b/stytch/b2c/otp/sms/sms.go @@ -3,6 +3,7 @@ package sms import ( "context" "encoding/json" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch" diff --git a/stytch/b2c/otp/whatsapp/whatsapp.go b/stytch/b2c/otp/whatsapp/whatsapp.go index 22e5e4e..54800ab 100644 --- a/stytch/b2c/otp/whatsapp/whatsapp.go +++ b/stytch/b2c/otp/whatsapp/whatsapp.go @@ -3,6 +3,7 @@ package whatsapp import ( "context" "encoding/json" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch" diff --git a/stytch/b2c/password/email/email.go b/stytch/b2c/password/email/email.go index 473c753..8d73940 100644 --- a/stytch/b2c/password/email/email.go +++ b/stytch/b2c/password/email/email.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch" diff --git a/stytch/b2c/password/existingpassword/existingpassword.go b/stytch/b2c/password/existingpassword/existingpassword.go index c52829e..a1f3fad 100644 --- a/stytch/b2c/password/existingpassword/existingpassword.go +++ b/stytch/b2c/password/existingpassword/existingpassword.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch" diff --git a/stytch/b2c/password/password.go b/stytch/b2c/password/password.go index efbce70..6df88d4 100644 --- a/stytch/b2c/password/password.go +++ b/stytch/b2c/password/password.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch/b2c/password/email" "github.com/stytchauth/stytch-go/v7/stytch/b2c/password/existingpassword" diff --git a/stytch/b2c/password/session/session.go b/stytch/b2c/password/session/session.go index 6f457d5..f307981 100644 --- a/stytch/b2c/password/session/session.go +++ b/stytch/b2c/password/session/session.go @@ -3,6 +3,7 @@ package session import ( "context" "encoding/json" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch" diff --git a/stytch/b2c/session/session.go b/stytch/b2c/session/session.go index 5ab1144..c4a4887 100644 --- a/stytch/b2c/session/session.go +++ b/stytch/b2c/session/session.go @@ -5,9 +5,10 @@ import ( "encoding/json" "errors" "fmt" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" "time" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/MicahParks/keyfunc" "github.com/golang-jwt/jwt/v4" "github.com/stytchauth/stytch-go/v7/stytch" diff --git a/stytch/b2c/session/session_test.go b/stytch/b2c/session/session_test.go index cd0a11e..c85d46c 100644 --- a/stytch/b2c/session/session_test.go +++ b/stytch/b2c/session/session_test.go @@ -5,15 +5,16 @@ import ( "crypto/rand" "crypto/rsa" "fmt" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/session" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/stytchapi" "net/http" "net/http/httptest" "strings" "testing" "time" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/session" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/stytchapi" + "github.com/MicahParks/keyfunc" "github.com/golang-jwt/jwt/v4" "github.com/stretchr/testify/assert" diff --git a/stytch/b2c/stytchapi/stytchapi.go b/stytch/b2c/stytchapi/stytchapi.go index 8c281d2..19296c2 100644 --- a/stytch/b2c/stytchapi/stytchapi.go +++ b/stytch/b2c/stytchapi/stytchapi.go @@ -3,6 +3,8 @@ package stytchapi import ( "context" "fmt" + "time" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/cryptowallet" "github.com/stytchauth/stytch-go/v7/stytch/b2c/magiclink" mle "github.com/stytchauth/stytch-go/v7/stytch/b2c/magiclink/email" @@ -19,7 +21,6 @@ import ( "github.com/stytchauth/stytch-go/v7/stytch/b2c/totp" "github.com/stytchauth/stytch-go/v7/stytch/b2c/user" "github.com/stytchauth/stytch-go/v7/stytch/b2c/webauthn" - "time" "github.com/MicahParks/keyfunc" "github.com/stytchauth/stytch-go/v7/stytch" diff --git a/stytch/b2c/stytchapi/stytchapi_test.go b/stytch/b2c/stytchapi/stytchapi_test.go index 6a5d0c8..e6d7113 100644 --- a/stytch/b2c/stytchapi/stytchapi_test.go +++ b/stytch/b2c/stytchapi/stytchapi_test.go @@ -2,13 +2,14 @@ package stytchapi_test import ( "context" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/stytchapi" "net/http" "net/http/httptest" "strings" "testing" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v7/stytch/b2c/stytchapi" + "github.com/stretchr/testify/assert" "github.com/stytchauth/stytch-go/v7/stytch" "github.com/stytchauth/stytch-go/v7/stytch/config" diff --git a/stytch/b2c/totp/totp.go b/stytch/b2c/totp/totp.go index 3a77c3d..b13dc0a 100644 --- a/stytch/b2c/totp/totp.go +++ b/stytch/b2c/totp/totp.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch" diff --git a/stytch/b2c/user/user.go b/stytch/b2c/user/user.go index df58019..a7e651e 100644 --- a/stytch/b2c/user/user.go +++ b/stytch/b2c/user/user.go @@ -3,9 +3,10 @@ package user import ( "context" "encoding/json" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" "strconv" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v7/stytch" "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" ) diff --git a/stytch/b2c/webauthn/webauthn.go b/stytch/b2c/webauthn/webauthn.go index 387fb1e..4315783 100644 --- a/stytch/b2c/webauthn/webauthn.go +++ b/stytch/b2c/webauthn/webauthn.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/stytchauth/stytch-go/v7/stytch/b2c" "github.com/stytchauth/stytch-go/v7/stytch" From 0e5532a0cd6303864df8c693faa26e24926763ee Mon Sep 17 00:00:00 2001 From: alex-stytch Date: Tue, 25 Apr 2023 14:39:50 -0700 Subject: [PATCH 03/12] update line-length --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index ff9e7eb..2eabfee 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,7 +6,7 @@ linters-settings: goimports: local-prefixes: github.com/stytchauth/stytch-go/stytch lll: - line-length: 100 + line-length: 150 issues: exclude-rules: # Ignore comments with long urls From 1b0612bdc6cfe459a1c8b8545ff95619c28a76c6 Mon Sep 17 00:00:00 2001 From: alex-stytch Date: Wed, 26 Apr 2023 12:37:33 -0700 Subject: [PATCH 04/12] organizations --- stytch/b2b/magiclink/magiclink.go | 2 +- stytch/b2b/organization.go | 82 +++++++++++++++++++ stytch/b2b/organization/organization.go | 103 ++++++++++++++++++++++++ 3 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 stytch/b2b/organization/organization.go diff --git a/stytch/b2b/magiclink/magiclink.go b/stytch/b2b/magiclink/magiclink.go index 41d589c..bd5c8b2 100644 --- a/stytch/b2b/magiclink/magiclink.go +++ b/stytch/b2b/magiclink/magiclink.go @@ -29,7 +29,7 @@ func (c *Client) Authenticate( if err != nil { return nil, stytcherror.NewClientLibraryError( "Oops, something seems to have gone wrong " + - "marshalling the /magic_links/authenticate request body") + "marshalling the /b2b/magic_links/authenticate request body") } } diff --git a/stytch/b2b/organization.go b/stytch/b2b/organization.go index b6e66e0..c2200e4 100644 --- a/stytch/b2b/organization.go +++ b/stytch/b2b/organization.go @@ -1,5 +1,70 @@ package b2b +import "encoding/json" + +type OrganizationCreateParams struct { + OrganizationName string `json:"organization_name"` + OrganizationSlug string `json:"organization_slug"` + OrganizationLogoURL string `json:"organization_logo_url,omitempty"` + TrustedMetadata map[string]any `json:"trusted_metadata,omitempty"` + SsoJitProvisioning string `json:"sso_jit_provisioning,omitempty"` + EmailAllowedDomains []string `json:"email_allowed_domains,omitempty"` + EmailJitProvisioning string `json:"email_jit_provisioning,omitempty"` + EmailInvites string `json:"email_invites,omitempty"` + AuthMethods string `json:"auth_methods,omitempty"` + AllowedAuthMethods []string `json:"allowed_auth_methods,omitempty"` +} +type OrganizationCreateResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + Organization Organization `json:"organization,omitempty"` +} + +type OrganizationGetResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + Organization Organization `json:"organization,omitempty"` +} + +type OrganizationUpdateParams struct { + OrganizationName string `json:"organization_name,omitempty"` + OrganizationSlug string `json:"organization_slug,omitempty"` + OrganizationLogoURL string `json:"organization_logo_url,omitempty"` + TrustedMetadata map[string]any `json:"trusted_metadata,omitempty"` + SsoDefaultConnectionID string `json:"sso_default_connection_id,omitempty"` + SsoJitProvisioning string `json:"sso_jit_provisioning,omitempty"` + SsoJitProvisioningAllowedConnections []string `json:"sso_jit_provisioning_allowed_connections,omitempty"` + EmailAllowedDomains []string `json:"email_allowed_domains,omitempty"` + EmailJitProvisioning string `json:"email_jit_provisioning,omitempty"` + EmailInvites string `json:"email_invites,omitempty"` + AuthMethods string `json:"auth_methods,omitempty"` + AllowedAuthMethods []string `json:"allowed_auth_methods,omitempty"` +} + +type OrganizationUpdateResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + Organization Organization `json:"organization,omitempty"` +} + +type OrganizationDeleteResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + OrganizationID string `json:"organization_id,omitempty"` +} + +type OrganizationSearchParams struct { + Cursor string `json:"cursor,omitempty"` + Limit uint32 `json:"limit,omitempty"` + Query OrganizationSearchQuery `json:"query,omitempty"` +} + +type OrganizationSearchResponse struct { + RequestID string `json:"request_id,omitempty"` + Organizations []Organization `json:"organizations,omitempty"` + ResultsMetadata ResultsMetadata `json:"results_metadata,omitempty"` +} + type Organization struct { OrganizationID string `json:"organization_id,omitempty"` OrganizationName string `json:"organization_name,omitempty"` @@ -44,3 +109,20 @@ type SSORegistrations struct { RegistrationID string `json:"registration_id,omitempty"` SSOAttributes map[string]interface{} `json:"sso_attributes,omitempty"` } + +type OrganizationSearchQuery struct { + Operator OrganizationSearchOperator `json:"operator,omitempty"` + Operands []json.Marshaler `json:"operands,omitempty"` +} + +type OrganizationSearchOperator string + +const ( + OrganizationSearchOperatorOR OrganizationSearchOperator = "OR" + OrganizationSearchOperatorAND OrganizationSearchOperator = "AND" +) + +type ResultsMetadata struct { + Total int `json:"total,omitempty"` + NextCursor string `json:"next_cursor,omitempty"` +} diff --git a/stytch/b2b/organization/organization.go b/stytch/b2b/organization/organization.go new file mode 100644 index 0000000..ff13225 --- /dev/null +++ b/stytch/b2b/organization/organization.go @@ -0,0 +1,103 @@ +package organization + +import ( + "context" + "encoding/json" + + "github.com/stytchauth/stytch-go/v7/stytch" + "github.com/stytchauth/stytch-go/v7/stytch/b2b" + "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" +) + +type Client struct { + C *stytch.Client +} + +func (c *Client) Create( + ctx context.Context, + body *b2b.OrganizationCreateParams, +) (*b2b.OrganizationCreateResponse, error) { + path := "/b2b/organizations" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the /b2b/organizations request body") + } + } + + var retVal b2b.OrganizationCreateResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} + +func (c *Client) Get( + ctx context.Context, + organizationID string, +) (*b2b.OrganizationGetResponse, error) { + path := "/b2b/organizations/" + organizationID + + var retVal b2b.OrganizationGetResponse + err := c.C.NewRequest(ctx, "GET", path, nil, nil, &retVal) + return &retVal, err +} + +func (c *Client) Update( + ctx context.Context, + organizationID string, + body *b2b.OrganizationUpdateParams, +) (*b2b.OrganizationUpdateResponse, error) { + path := "/b2b/organizations" + organizationID + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the update organization request body") + } + } + + var retVal b2b.OrganizationUpdateResponse + err = c.C.NewRequest(ctx, "PUT", path, nil, jsonBody, &retVal) + return &retVal, err +} + +func (c *Client) Delete( + ctx context.Context, + organizationID string, +) (*b2b.OrganizationDeleteResponse, error) { + path := "/b2b/organizations/" + organizationID + + var retVal b2b.OrganizationDeleteResponse + err := c.C.NewRequest(ctx, "DELETE", path, nil, nil, &retVal) + return &retVal, err +} + +func (c *Client) Search( + ctx context.Context, + body *b2b.OrganizationSearchParams, +) (*b2b.OrganizationSearchResponse, error) { + path := "/b2b/organizations/search" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the /b2b/organizations/search request body") + } + } + + var retVal b2b.OrganizationSearchResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} From f94a3a8aa1d83ad831c3cf48c5ece6e58232b53a Mon Sep 17 00:00:00 2001 From: alex-stytch Date: Wed, 26 Apr 2023 12:59:39 -0700 Subject: [PATCH 05/12] members --- stytch/b2b/b2bstytchapi/b2bstytchapi.go | 9 +- stytch/b2b/organization.go | 82 ++++++++++++++++-- stytch/b2b/organization/organization.go | 105 +++++++++++++++++++++++- 3 files changed, 187 insertions(+), 9 deletions(-) diff --git a/stytch/b2b/b2bstytchapi/b2bstytchapi.go b/stytch/b2b/b2bstytchapi/b2bstytchapi.go index 5adfdbc..8b55085 100644 --- a/stytch/b2b/b2bstytchapi/b2bstytchapi.go +++ b/stytch/b2b/b2bstytchapi/b2bstytchapi.go @@ -4,6 +4,7 @@ import ( "github.com/stytchauth/stytch-go/v7/stytch" "github.com/stytchauth/stytch-go/v7/stytch/b2b/magiclink" mle "github.com/stytchauth/stytch-go/v7/stytch/b2b/magiclink/email" + "github.com/stytchauth/stytch-go/v7/stytch/b2b/organization" "github.com/stytchauth/stytch-go/v7/stytch/config" ) @@ -12,9 +13,10 @@ type Logger interface { } type API struct { - client *stytch.Client - logger Logger - MagicLinks *magiclink.Client + client *stytch.Client + logger Logger + MagicLinks *magiclink.Client + Organization *organization.Client } type Option func(*API) @@ -41,5 +43,6 @@ func NewAPIClient(env config.Env, projectID string, secret string, opts ...Optio } a.MagicLinks = &magiclink.Client{C: a.client, Email: &mle.Client{C: a.client}} + a.Organization = &organization.Client{C: a.client} return a, nil } diff --git a/stytch/b2b/organization.go b/stytch/b2b/organization.go index c2200e4..53fe298 100644 --- a/stytch/b2b/organization.go +++ b/stytch/b2b/organization.go @@ -61,10 +61,77 @@ type OrganizationSearchParams struct { type OrganizationSearchResponse struct { RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` Organizations []Organization `json:"organizations,omitempty"` ResultsMetadata ResultsMetadata `json:"results_metadata,omitempty"` } +// MEMBERS + +type OrganizationMemberCreateParams struct { + EmailAddress string `json:"email_address,omitempty"` + Name string `json:"name,omitempty"` + TrustedMetadata map[string]any `json:"trusted_metadata,omitempty"` + UntrustedMetadata map[string]any `json:"untrusted_metadata,omitempty"` + CreateMemberAsPending bool `json:"create_member_as_pending,omitempty"` + IsBreakglass bool `json:"is_breakglass,omitempty"` +} + +type OrganizationMemberCreateResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + MemberID string `json:"member_id,omitempty"` + Member Member `json:"member,omitempty"` + Organization Organization `json:"organization,omitempty"` +} + +type OrganizationMemberUpdateParams struct { + Name string `json:"name,omitempty"` + TrustedMetadata map[string]any `json:"trusted_metadata,omitempty"` + UntrustedMetadata map[string]any `json:"untrusted_metadata,omitempty"` + IsBreakglass bool `json:"is_breakglass,omitempty"` +} +type OrganizationMemberUpdateResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + MemberID string `json:"member_id,omitempty"` + Member Member `json:"member,omitempty"` + Organization Organization `json:"organization,omitempty"` +} + +type OrganizationMemberDeleteResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + MemberID string `json:"member_id,omitempty"` +} + +type OrganizationMemberSearchParams struct { + Cursor string `json:"cursor,omitempty"` + Limit uint32 `json:"limit,omitempty"` + Query MemberSearchQuery `json:"query,omitempty"` + OrganizationIds []string `json:"organization_ids,omitempty"` +} + +type OrganizationMemberSearchResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + Members []Member `json:"members,omitempty"` + ResultsMetadata ResultsMetadata `json:"results_metadata,omitempty"` +} + +type OrganizationMemberGetParams struct { + MemberID string `json:"member_id,omitempty"` + EmailAddress string `json:"email_address,omitempty"` +} + +type OrganizationMemberGetResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + MemberID string `json:"member_id,omitempty"` + Member Member `json:"member,omitempty"` + Organization Organization `json:"organization,omitempty"` +} + type Organization struct { OrganizationID string `json:"organization_id,omitempty"` OrganizationName string `json:"organization_name,omitempty"` @@ -111,18 +178,23 @@ type SSORegistrations struct { } type OrganizationSearchQuery struct { - Operator OrganizationSearchOperator `json:"operator,omitempty"` - Operands []json.Marshaler `json:"operands,omitempty"` + Operator SearchOperator `json:"operator,omitempty"` + Operands []json.Marshaler `json:"operands,omitempty"` } -type OrganizationSearchOperator string +type SearchOperator string const ( - OrganizationSearchOperatorOR OrganizationSearchOperator = "OR" - OrganizationSearchOperatorAND OrganizationSearchOperator = "AND" + SearchOperatorOR SearchOperator = "OR" + SearchOperatorAND SearchOperator = "AND" ) type ResultsMetadata struct { Total int `json:"total,omitempty"` NextCursor string `json:"next_cursor,omitempty"` } + +type MemberSearchQuery struct { + Operator SearchOperator `json:"operator,omitempty"` + Operands []json.Marshaler `json:"operands,omitempty"` +} diff --git a/stytch/b2b/organization/organization.go b/stytch/b2b/organization/organization.go index ff13225..5dc824b 100644 --- a/stytch/b2b/organization/organization.go +++ b/stytch/b2b/organization/organization.go @@ -51,7 +51,7 @@ func (c *Client) Update( organizationID string, body *b2b.OrganizationUpdateParams, ) (*b2b.OrganizationUpdateResponse, error) { - path := "/b2b/organizations" + organizationID + path := "/b2b/organizations/" + organizationID var jsonBody []byte var err error @@ -101,3 +101,106 @@ func (c *Client) Search( err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } + +func (c *Client) MemberCreate( + ctx context.Context, + organizationID string, + body *b2b.OrganizationMemberCreateParams, +) (*b2b.OrganizationMemberCreateResponse, error) { + path := "/b2b/organizations/" + organizationID + "/members" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the member create request body") + } + } + + var retVal b2b.OrganizationMemberCreateResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} + +func (c *Client) MemberGet( + ctx context.Context, + organizationID string, + body *b2b.OrganizationMemberGetParams, +) (*b2b.OrganizationMemberGetResponse, error) { + path := "/b2b/organizations/" + organizationID + "/member" + + queryParams := make(map[string]string) + if body != nil { + if body.MemberID != "" { + queryParams["member_id"] = body.MemberID + } + if body.EmailAddress != "" { + queryParams["email_address"] = body.EmailAddress + } + } + + var retVal b2b.OrganizationMemberGetResponse + err := c.C.NewRequest(ctx, "GET", path, queryParams, nil, &retVal) + return &retVal, err +} + +func (c *Client) MemberUpdate( + ctx context.Context, + organizationID string, + memberID string, + body *b2b.OrganizationMemberUpdateParams, +) (*b2b.OrganizationMemberUpdateResponse, error) { + path := "/b2b/organizations/" + organizationID + "/members" + memberID + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the update member request body") + } + } + + var retVal b2b.OrganizationMemberUpdateResponse + err = c.C.NewRequest(ctx, "PUT", path, nil, jsonBody, &retVal) + return &retVal, err +} + +func (c *Client) MemberDelete( + ctx context.Context, + organizationID string, + memberID string, +) (*b2b.OrganizationMemberDeleteResponse, error) { + path := "/b2b/organizations/" + organizationID + "/members/" + memberID + + var retVal b2b.OrganizationMemberDeleteResponse + err := c.C.NewRequest(ctx, "DELETE", path, nil, nil, &retVal) + return &retVal, err +} + +func (c *Client) MemberSearch( + ctx context.Context, + body *b2b.OrganizationMemberSearchParams, +) (*b2b.OrganizationMemberSearchResponse, error) { + path := "/b2b/organizations/members/search" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the /b2b/organizations/members/search request body") + } + } + + var retVal b2b.OrganizationMemberSearchResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} From 25d950299f08dd12d5fc434c6e66b46403a1ec8e Mon Sep 17 00:00:00 2001 From: alex-stytch Date: Thu, 27 Apr 2023 10:34:18 -0700 Subject: [PATCH 06/12] magic links --- stytch/b2b/discovery.go | 13 ++++++++ stytch/b2b/magiclink.go | 45 ++++++++++++++++++++++++++++ stytch/b2b/magiclink/email/email.go | 46 +++++++++++++++++++++++++++++ stytch/b2b/magiclink/magiclink.go | 22 ++++++++++++++ 4 files changed, 126 insertions(+) create mode 100644 stytch/b2b/discovery.go diff --git a/stytch/b2b/discovery.go b/stytch/b2b/discovery.go new file mode 100644 index 0000000..a7983af --- /dev/null +++ b/stytch/b2b/discovery.go @@ -0,0 +1,13 @@ +package b2b + +type DiscoveredOrganization struct { + Organization Organization `json:"organization,omitempty"` + Membership Membership `json:"membership,omitempty"` + MemberAuthenticated bool `json:"member_authenticated,omitempty"` +} + +type Membership struct { + Type string `json:"type,omitempty"` + Details map[string]interface{} `json:"details,omitempty"` + Member Member `json:"member,omitempty"` +} diff --git a/stytch/b2b/magiclink.go b/stytch/b2b/magiclink.go index cead785..01b50f7 100644 --- a/stytch/b2b/magiclink.go +++ b/stytch/b2b/magiclink.go @@ -23,6 +23,19 @@ type MagicLinksAuthenticateResponse struct { Organization Organization `json:"organization,omitempty"` } +type MagicLinksDiscoveryAuthenticateParams struct { + DiscoveryMagicLinksToken string `json:"discovery_magic_links_token"` + PKCECodeVerifier string `json:"pkce_code_verifier,omitempty"` +} + +type MagicLinksDiscoveryAuthenticateResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + IntermediateSessionToken string `json:"intermediate_session_token,omitempty"` + EmailAddress string `json:"email_address,omitempty"` + DiscoveredOrganizations []DiscoveredOrganization `json:"discovered_organizations,omitempty"` +} + // MAGIC LINK - EMAIL type MagicLinksEmailLoginOrSignupParams struct { OrganizationID string `json:"organization_id"` @@ -44,3 +57,35 @@ type MagicLinksEmailLoginOrSignupResponse struct { Member Member `json:"member,omitempty"` Organization Organization `json:"organization,omitempty"` } + +type MagicLinksEmailInviteParams struct { + OrganizationID string `json:"organization_id"` + EmailAddress string `json:"email_address"` + InviteRedirectURL string `json:"invite_redirect_url,omitempty"` + InvitedByMemberID string `json:"invited_by_member_id,omitempty"` + Name string `json:"name,omitempty"` + TrustedMetadata map[string]any `json:"trusted_metadata,omitempty"` + UntrustedMetadata map[string]any `json:"untrusted_metadata,omitempty"` + InviteTemplateID string `json:"invite_template_id,omitempty"` + Locale string `json:"locale,omitempty"` +} +type MagicLinksEmailInviteResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + MemberID string `json:"member_id,omitempty"` + Member Member `json:"member,omitempty"` + Organization Organization `json:"organization,omitempty"` +} + +type MagicLinksEmailDiscoverySendParams struct { + EmailAddress string `json:"email_address"` + DiscoveryRedirectURL string `json:"discovery_redirect_url,omitempty"` + PkceCodeChallenge string `json:"pkce_code_challenge,omitempty"` + LoginTemplateID string `json:"login_template_id,omitempty"` + Locale string `json:"locale,omitempty"` +} + +type MagicLinksEmailDiscoverySendResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` +} diff --git a/stytch/b2b/magiclink/email/email.go b/stytch/b2b/magiclink/email/email.go index 7813cfd..8eecbd7 100644 --- a/stytch/b2b/magiclink/email/email.go +++ b/stytch/b2b/magiclink/email/email.go @@ -35,3 +35,49 @@ func (c *Client) LoginOrSignup( err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } + +func (c *Client) Invite( + ctx context.Context, + body *b2b.MagicLinksEmailInviteParams, +) ( + *b2b.MagicLinksEmailInviteResponse, error, +) { + path := "/b2b/magic_links/email/invite" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError("Oops, something seems to have gone wrong " + + "marshalling the /b2b/magic_links/email/invite request body") + } + } + + var retVal b2b.MagicLinksEmailInviteResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} + +func (c *Client) DiscoverySend( + ctx context.Context, + body *b2b.MagicLinksEmailDiscoverySendParams, +) ( + *b2b.MagicLinksEmailDiscoverySendResponse, error, +) { + path := "/b2b/magic_links/email/discovery/send" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError("Oops, something seems to have gone wrong " + + "marshalling the /b2b/magic_links/email/discovery/send request body") + } + } + + var retVal b2b.MagicLinksEmailDiscoverySendResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} diff --git a/stytch/b2b/magiclink/magiclink.go b/stytch/b2b/magiclink/magiclink.go index bd5c8b2..b3153d1 100644 --- a/stytch/b2b/magiclink/magiclink.go +++ b/stytch/b2b/magiclink/magiclink.go @@ -37,3 +37,25 @@ func (c *Client) Authenticate( err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) return &retVal, err } + +func (c *Client) DiscoveryAuthenticate( + ctx context.Context, + body *b2b.MagicLinksDiscoveryAuthenticateParams, +) (*b2b.MagicLinksEmailDiscoverySendResponse, error) { + path := "/b2b/magic_links/discovery/authenticate" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the /b2b/magic_links/discovery/authenticate request body") + } + } + + var retVal b2b.MagicLinksEmailDiscoverySendResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} From 1a4d8536b1f0fc86890dc01911f7a07d929f4c8b Mon Sep 17 00:00:00 2001 From: alex-stytch Date: Thu, 27 Apr 2023 11:00:32 -0700 Subject: [PATCH 07/12] sessions --- stytch/b2b/b2bstytchapi/b2bstytchapi.go | 3 + stytch/b2b/session.go | 72 +++++++++++++++++- stytch/b2b/session/session.go | 97 +++++++++++++++++++++++++ 3 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 stytch/b2b/session/session.go diff --git a/stytch/b2b/b2bstytchapi/b2bstytchapi.go b/stytch/b2b/b2bstytchapi/b2bstytchapi.go index 8b55085..d7f048d 100644 --- a/stytch/b2b/b2bstytchapi/b2bstytchapi.go +++ b/stytch/b2b/b2bstytchapi/b2bstytchapi.go @@ -5,6 +5,7 @@ import ( "github.com/stytchauth/stytch-go/v7/stytch/b2b/magiclink" mle "github.com/stytchauth/stytch-go/v7/stytch/b2b/magiclink/email" "github.com/stytchauth/stytch-go/v7/stytch/b2b/organization" + "github.com/stytchauth/stytch-go/v7/stytch/b2b/session" "github.com/stytchauth/stytch-go/v7/stytch/config" ) @@ -17,6 +18,7 @@ type API struct { logger Logger MagicLinks *magiclink.Client Organization *organization.Client + Session *session.Client } type Option func(*API) @@ -44,5 +46,6 @@ func NewAPIClient(env config.Env, projectID string, secret string, opts ...Optio a.MagicLinks = &magiclink.Client{C: a.client, Email: &mle.Client{C: a.client}} a.Organization = &organization.Client{C: a.client} + a.Session = &session.Client{C: a.client} return a, nil } diff --git a/stytch/b2b/session.go b/stytch/b2b/session.go index 1206dd6..d806a6f 100644 --- a/stytch/b2b/session.go +++ b/stytch/b2b/session.go @@ -1,3 +1,73 @@ package b2b -type MemberSession struct{} +import "github.com/stytchauth/stytch-go/v7/stytch/b2c" + +type SessionGetParams struct { + OrganizationID string `json:"organization_id"` + MemberID string `json:"member_id"` +} + +type SessionGetResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + MemberSessions []MemberSession `json:"member_sessions,omitempty"` +} + +type SessionAuthenticateParams struct { + SessionToken string `json:"session_token,omitempty"` + SessionDurationMinutes int32 `json:"session_duration_minutes,omitempty"` + SessionJWT string `json:"session_jwt,omitempty"` + SessionCustomClaims map[string]interface{} `json:"session_custom_claims,omitempty"` +} + +type SessionAuthenticateResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + MemberSession MemberSession `json:"member_session,omitempty"` + SessionToken string `json:"session_token,omitempty"` + SessionJWT string `json:"session_jwt,omitempty"` + Member Member `json:"member,omitempty"` + Organization Organization `json:"organization,omitempty"` +} + +type SessionRevokeParams struct { + MemberSessionID string `json:"member_session_id,omitempty"` + SessionToken string `json:"session_token,omitempty"` + SessionJWT string `json:"session_jwt,omitempty"` + MemberID string `json:"member_id,omitempty"` +} + +type SessionRevokeResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` +} + +type SessionExchangeParams struct { + OrganizationID string `json:"organization_id,omitempty"` + SessionToken string `json:"session_token,omitempty"` + SessionJWT string `json:"session_jwt,omitempty"` + SessionDurationMinutes int32 `json:"session_duration_minutes,omitempty"` + SessionCustomClaims map[string]interface{} `json:"session_custom_claims,omitempty"` +} + +type SessionExchangeResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + MemberID string `json:"member_id,omitempty"` + MemberSession MemberSession `json:"member_session,omitempty"` + SessionToken string `json:"session_token,omitempty"` + SessionJWT string `json:"session_jwt,omitempty"` + Member Member `json:"member,omitempty"` + Organization Organization `json:"organization,omitempty"` +} + +type MemberSession struct { + MemberSessionID string `json:"member_session_id,omitempty"` + MemberID string `json:"member_id,omitempty"` + StartedAt string `json:"started_at,omitempty"` + LastAccessedAt string `json:"last_accessed_at,omitempty"` + ExpiresAt string `json:"expires_at,omitempty"` + AuthenticationFactors []*b2c.AuthenticationFactor `json:"authentication_factors,omitempty"` + CustomClaims interface{} `json:"custom_claims,omitempty"` + OrganizationID string `json:"organization_id,omitempty"` +} diff --git a/stytch/b2b/session/session.go b/stytch/b2b/session/session.go new file mode 100644 index 0000000..76e042d --- /dev/null +++ b/stytch/b2b/session/session.go @@ -0,0 +1,97 @@ +package session + +import ( + "context" + "encoding/json" + + "github.com/stytchauth/stytch-go/v7/stytch" + "github.com/stytchauth/stytch-go/v7/stytch/b2b" + "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" +) + +type Client struct { + C *stytch.Client +} + +func (c *Client) Get( + ctx context.Context, + body *b2b.SessionGetParams, +) (*b2b.SessionGetResponse, error) { + path := "/b2b/sessions" + + queryParams := make(map[string]string) + if body != nil { + queryParams["organization_id"] = body.OrganizationID + queryParams["member_id"] = body.MemberID + } + + var retVal b2b.SessionGetResponse + err := c.C.NewRequest(ctx, "GET", path, queryParams, nil, &retVal) + return &retVal, err +} + +func (c *Client) Authenticate( + ctx context.Context, + body *b2b.SessionAuthenticateParams, +) (*b2b.SessionAuthenticateResponse, error) { + path := "/b2b/sessions/authenticate" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the /b2b/sessions/authenticate request body") + } + } + + var retVal b2b.SessionAuthenticateResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} + +func (c *Client) Revoke( + ctx context.Context, + body *b2b.SessionRevokeParams, +) (*b2b.SessionRevokeResponse, error) { + path := "/b2b/sessions/revoke" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the /b2b/sessions/revoke request body") + } + } + + var retVal b2b.SessionRevokeResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} + +func (c *Client) Exchange( + ctx context.Context, + body *b2b.SessionExchangeParams, +) (*b2b.SessionExchangeResponse, error) { + path := "/b2b/sessions/exchange" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the /b2b/sessions/exchange request body") + } + } + + var retVal b2b.SessionExchangeResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} From 091414331e705c78f6a689bc250aad1b4bca6d83 Mon Sep 17 00:00:00 2001 From: alex-stytch Date: Thu, 27 Apr 2023 11:37:49 -0700 Subject: [PATCH 08/12] discovery --- stytch/b2b/b2bstytchapi/b2bstytchapi.go | 3 + stytch/b2b/discovery.go | 58 ++++++++++++++++++ stytch/b2b/discovery/discovery.go | 80 +++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 stytch/b2b/discovery/discovery.go diff --git a/stytch/b2b/b2bstytchapi/b2bstytchapi.go b/stytch/b2b/b2bstytchapi/b2bstytchapi.go index d7f048d..405eac8 100644 --- a/stytch/b2b/b2bstytchapi/b2bstytchapi.go +++ b/stytch/b2b/b2bstytchapi/b2bstytchapi.go @@ -2,6 +2,7 @@ package b2bstytchapi import ( "github.com/stytchauth/stytch-go/v7/stytch" + "github.com/stytchauth/stytch-go/v7/stytch/b2b/discovery" "github.com/stytchauth/stytch-go/v7/stytch/b2b/magiclink" mle "github.com/stytchauth/stytch-go/v7/stytch/b2b/magiclink/email" "github.com/stytchauth/stytch-go/v7/stytch/b2b/organization" @@ -19,6 +20,7 @@ type API struct { MagicLinks *magiclink.Client Organization *organization.Client Session *session.Client + Discovery *discovery.Client } type Option func(*API) @@ -47,5 +49,6 @@ func NewAPIClient(env config.Env, projectID string, secret string, opts ...Optio a.MagicLinks = &magiclink.Client{C: a.client, Email: &mle.Client{C: a.client}} a.Organization = &organization.Client{C: a.client} a.Session = &session.Client{C: a.client} + a.Discovery = &discovery.Client{C: a.client} return a, nil } diff --git a/stytch/b2b/discovery.go b/stytch/b2b/discovery.go index a7983af..67b6c68 100644 --- a/stytch/b2b/discovery.go +++ b/stytch/b2b/discovery.go @@ -1,5 +1,63 @@ package b2b +type DiscoveryListOrganizationsParams struct { + IntermediateSessionToken string `json:"intermediate_session_token,omitempty"` + SessionToken string `json:"session_token,omitempty"` + SessionJwt string `json:"session_jwt,omitempty"` +} + +type DiscoveryListOrganizationsResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + EmailAddress string `json:"email_address,omitempty"` + DiscoveredOrganizations []DiscoveredOrganization `json:"discovered_organizations,omitempty"` +} + +type DiscoveryIntermediateSessionExchangeParams struct { + IntermediateSessionToken string `json:"intermediate_session_token"` + OrganizationID string `json:"organization_id"` + SessionDurationMinutes int32 `json:"session_duration_minutes,omitempty"` + SessionCustomClaims map[string]any `json:"session_custom_claims,omitempty"` +} + +type DiscoveryIntermediateSessionExchangeResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + MemberID string `json:"member_id,omitempty"` + MemberSession MemberSession `json:"member_session,omitempty"` + SessionToken string `json:"session_token,omitempty"` + SessionJWT string `json:"session_jwt,omitempty"` + Member Member `json:"member,omitempty"` + Organization Organization `json:"organization,omitempty"` +} + +type DiscoveryOrganizationCreateParams struct { + IntermediateSessionToken string `json:"intermediate_session_token"` + SessionDurationMinutes int32 `json:"session_duration_minutes,omitempty"` + SessionCustomClaims map[string]any `json:"session_custom_claims,omitempty"` + OrganizationName string `json:"organization_name,omitempty"` + OrganizationSlug string `json:"organization_slug,omitempty"` + OrganizationLogoURL string `json:"organization_logo_url,omitempty"` + TrustedMetadata map[string]any `json:"trusted_metadata,omitempty"` + SsoJitProvisioning string `json:"sso_jit_provisioning,omitempty"` + EmailAllowedDomains []string `json:"email_allowed_domains,omitempty"` + EmailJitProvisioning string `json:"email_jit_provisioning,omitempty"` + EmailInvites string `json:"email_invites,omitempty"` + AuthMethods string `json:"auth_methods,omitempty"` + AllowedAuthMethods []string `json:"allowed_auth_methods,omitempty"` +} + +type DiscoveryOrganizationCreateResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + MemberID string `json:"member_id,omitempty"` + MemberSession MemberSession `json:"member_session,omitempty"` + SessionToken string `json:"session_token,omitempty"` + SessionJWT string `json:"session_jwt,omitempty"` + Member Member `json:"member,omitempty"` + Organization Organization `json:"organization,omitempty"` +} + type DiscoveredOrganization struct { Organization Organization `json:"organization,omitempty"` Membership Membership `json:"membership,omitempty"` diff --git a/stytch/b2b/discovery/discovery.go b/stytch/b2b/discovery/discovery.go new file mode 100644 index 0000000..ec3015b --- /dev/null +++ b/stytch/b2b/discovery/discovery.go @@ -0,0 +1,80 @@ +package discovery + +import ( + "context" + "encoding/json" + + "github.com/stytchauth/stytch-go/v7/stytch" + "github.com/stytchauth/stytch-go/v7/stytch/b2b" + "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" +) + +type Client struct { + C *stytch.Client +} + +func (c *Client) List( + ctx context.Context, + body *b2b.DiscoveryListOrganizationsParams, +) (*b2b.DiscoveryListOrganizationsResponse, error) { + path := "/b2b/discovery/organizations" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the /b2b/discovery/organizations request body") + } + } + + var retVal b2b.DiscoveryListOrganizationsResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} + +func (c *Client) IntermediateSessionExchange( + ctx context.Context, + body *b2b.DiscoveryIntermediateSessionExchangeParams, +) (*b2b.DiscoveryIntermediateSessionExchangeResponse, error) { + path := "/b2b/discovery/intermediate_sessions/exchange" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the /b2b/discovery/intermediate_sessions/exchange request body") + } + } + + var retVal b2b.DiscoveryIntermediateSessionExchangeResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} + +func (c *Client) OrganizationCreate( + ctx context.Context, + body *b2b.DiscoveryOrganizationCreateParams, +) (*b2b.DiscoveryOrganizationCreateResponse, error) { + path := "/b2b/discovery/organizations/create" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the /b2b/discovery/organizations/create request body") + } + } + + var retVal b2b.DiscoveryOrganizationCreateResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} From 2e64d1ef9cf458d581a07e295dab05432630d513 Mon Sep 17 00:00:00 2001 From: alex-stytch Date: Fri, 28 Apr 2023 10:08:54 -0700 Subject: [PATCH 09/12] v8 --- README.md | 6 ++-- go.mod | 2 +- stytch/b2b/b2bstytchapi/b2bstytchapi.go | 14 ++++---- stytch/b2b/discovery/discovery.go | 6 ++-- stytch/b2b/magiclink/email/email.go | 6 ++-- stytch/b2b/magiclink/magiclink.go | 8 ++--- stytch/b2b/organization/organization.go | 6 ++-- stytch/b2b/session.go | 2 +- stytch/b2b/session/session.go | 6 ++-- stytch/b2c/cryptowallet/cryptowallet.go | 6 ++-- stytch/b2c/magiclink/email/email.go | 6 ++-- stytch/b2c/magiclink/magiclink.go | 8 ++--- stytch/b2c/oauth/oauth.go | 8 ++--- stytch/b2c/otp/email/email.go | 6 ++-- stytch/b2c/otp/otp.go | 12 +++---- stytch/b2c/otp/sms/sms.go | 6 ++-- stytch/b2c/otp/whatsapp/whatsapp.go | 6 ++-- stytch/b2c/password/email/email.go | 6 ++-- .../existingpassword/existingpassword.go | 6 ++-- stytch/b2c/password/password.go | 12 +++---- stytch/b2c/password/session/session.go | 6 ++-- stytch/b2c/session/session.go | 6 ++-- stytch/b2c/session/session_test.go | 10 +++--- stytch/b2c/stytchapi/stytchapi.go | 36 +++++++++---------- stytch/b2c/stytchapi/stytchapi_test.go | 8 ++--- stytch/b2c/totp/totp.go | 6 ++-- stytch/b2c/user/user.go | 6 ++-- stytch/b2c/webauthn/webauthn.go | 6 ++-- stytch/config/config.go | 2 +- stytch/stytch.go | 4 +-- stytch/stytcherror/stytcherror.go | 2 +- 31 files changed, 115 insertions(+), 115 deletions(-) diff --git a/README.md b/README.md index a5de380..0c7c5c7 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ It pairs well with the Stytch [Web SDK](https://www.npmjs.com/package/@stytch/st ## Install ```console -$ go get github.com/stytchauth/stytch-go/v7 +$ go get github.com/stytchauth/stytch-go/v8 ``` ## Usage @@ -34,8 +34,8 @@ Create an API client: import ( "os" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/stytchapi" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytchapi" ) stytchAPIClient, err := stytchapi.NewAPIClient( diff --git a/go.mod b/go.mod index 6a8205f..780f7e9 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/stytchauth/stytch-go/v7 +module github.com/stytchauth/stytch-go/v8 go 1.18 diff --git a/stytch/b2b/b2bstytchapi/b2bstytchapi.go b/stytch/b2b/b2bstytchapi/b2bstytchapi.go index 405eac8..9ac3dd0 100644 --- a/stytch/b2b/b2bstytchapi/b2bstytchapi.go +++ b/stytch/b2b/b2bstytchapi/b2bstytchapi.go @@ -1,13 +1,13 @@ package b2bstytchapi import ( - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/b2b/discovery" - "github.com/stytchauth/stytch-go/v7/stytch/b2b/magiclink" - mle "github.com/stytchauth/stytch-go/v7/stytch/b2b/magiclink/email" - "github.com/stytchauth/stytch-go/v7/stytch/b2b/organization" - "github.com/stytchauth/stytch-go/v7/stytch/b2b/session" - "github.com/stytchauth/stytch-go/v7/stytch/config" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/b2b/discovery" + "github.com/stytchauth/stytch-go/v8/stytch/b2b/magiclink" + mle "github.com/stytchauth/stytch-go/v8/stytch/b2b/magiclink/email" + "github.com/stytchauth/stytch-go/v8/stytch/b2b/organization" + "github.com/stytchauth/stytch-go/v8/stytch/b2b/session" + "github.com/stytchauth/stytch-go/v8/stytch/config" ) type Logger interface { diff --git a/stytch/b2b/discovery/discovery.go b/stytch/b2b/discovery/discovery.go index ec3015b..2dd83eb 100644 --- a/stytch/b2b/discovery/discovery.go +++ b/stytch/b2b/discovery/discovery.go @@ -4,9 +4,9 @@ import ( "context" "encoding/json" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/b2b" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/b2b" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) type Client struct { diff --git a/stytch/b2b/magiclink/email/email.go b/stytch/b2b/magiclink/email/email.go index 8eecbd7..b3e100e 100644 --- a/stytch/b2b/magiclink/email/email.go +++ b/stytch/b2b/magiclink/email/email.go @@ -4,9 +4,9 @@ import ( "context" "encoding/json" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/b2b" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/b2b" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) type Client struct { diff --git a/stytch/b2b/magiclink/magiclink.go b/stytch/b2b/magiclink/magiclink.go index b3153d1..aec3725 100644 --- a/stytch/b2b/magiclink/magiclink.go +++ b/stytch/b2b/magiclink/magiclink.go @@ -4,11 +4,11 @@ import ( "context" "encoding/json" - "github.com/stytchauth/stytch-go/v7/stytch/b2b" - "github.com/stytchauth/stytch-go/v7/stytch/b2b/magiclink/email" + "github.com/stytchauth/stytch-go/v8/stytch/b2b" + "github.com/stytchauth/stytch-go/v8/stytch/b2b/magiclink/email" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) type Client struct { diff --git a/stytch/b2b/organization/organization.go b/stytch/b2b/organization/organization.go index 5dc824b..1e1609b 100644 --- a/stytch/b2b/organization/organization.go +++ b/stytch/b2b/organization/organization.go @@ -4,9 +4,9 @@ import ( "context" "encoding/json" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/b2b" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/b2b" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) type Client struct { diff --git a/stytch/b2b/session.go b/stytch/b2b/session.go index d806a6f..5701c44 100644 --- a/stytch/b2b/session.go +++ b/stytch/b2b/session.go @@ -1,6 +1,6 @@ package b2b -import "github.com/stytchauth/stytch-go/v7/stytch/b2c" +import "github.com/stytchauth/stytch-go/v8/stytch/b2c" type SessionGetParams struct { OrganizationID string `json:"organization_id"` diff --git a/stytch/b2b/session/session.go b/stytch/b2b/session/session.go index 76e042d..1650339 100644 --- a/stytch/b2b/session/session.go +++ b/stytch/b2b/session/session.go @@ -4,9 +4,9 @@ import ( "context" "encoding/json" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/b2b" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/b2b" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) type Client struct { diff --git a/stytch/b2c/cryptowallet/cryptowallet.go b/stytch/b2c/cryptowallet/cryptowallet.go index 5e66fab..b02d3fd 100644 --- a/stytch/b2c/cryptowallet/cryptowallet.go +++ b/stytch/b2c/cryptowallet/cryptowallet.go @@ -5,10 +5,10 @@ import ( "encoding/json" "fmt" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v8/stytch/b2c" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) type Client struct { diff --git a/stytch/b2c/magiclink/email/email.go b/stytch/b2c/magiclink/email/email.go index a5cfea4..725f200 100644 --- a/stytch/b2c/magiclink/email/email.go +++ b/stytch/b2c/magiclink/email/email.go @@ -4,10 +4,10 @@ import ( "context" "encoding/json" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v8/stytch/b2c" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) type Client struct { diff --git a/stytch/b2c/magiclink/magiclink.go b/stytch/b2c/magiclink/magiclink.go index 149dde6..c4751d9 100644 --- a/stytch/b2c/magiclink/magiclink.go +++ b/stytch/b2c/magiclink/magiclink.go @@ -5,11 +5,11 @@ import ( "encoding/json" "fmt" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/magiclink/email" + "github.com/stytchauth/stytch-go/v8/stytch/b2c" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/magiclink/email" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) type Client struct { diff --git a/stytch/b2c/oauth/oauth.go b/stytch/b2c/oauth/oauth.go index 391239d..e1ffc5d 100644 --- a/stytch/b2c/oauth/oauth.go +++ b/stytch/b2c/oauth/oauth.go @@ -5,11 +5,11 @@ import ( "encoding/json" "fmt" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/magiclink/email" + "github.com/stytchauth/stytch-go/v8/stytch/b2c" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/magiclink/email" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) type Client struct { diff --git a/stytch/b2c/otp/email/email.go b/stytch/b2c/otp/email/email.go index 95a67e1..1c4026e 100644 --- a/stytch/b2c/otp/email/email.go +++ b/stytch/b2c/otp/email/email.go @@ -4,10 +4,10 @@ import ( "context" "encoding/json" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v8/stytch/b2c" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) type Client struct { diff --git a/stytch/b2c/otp/otp.go b/stytch/b2c/otp/otp.go index ecbb3bf..bf508bd 100644 --- a/stytch/b2c/otp/otp.go +++ b/stytch/b2c/otp/otp.go @@ -5,13 +5,13 @@ import ( "encoding/json" "fmt" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/otp/email" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/otp/sms" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/otp/whatsapp" + "github.com/stytchauth/stytch-go/v8/stytch/b2c" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/otp/email" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/otp/sms" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/otp/whatsapp" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) type Client struct { diff --git a/stytch/b2c/otp/sms/sms.go b/stytch/b2c/otp/sms/sms.go index 37b1f3c..53072ee 100644 --- a/stytch/b2c/otp/sms/sms.go +++ b/stytch/b2c/otp/sms/sms.go @@ -4,10 +4,10 @@ import ( "context" "encoding/json" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v8/stytch/b2c" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) type Client struct { diff --git a/stytch/b2c/otp/whatsapp/whatsapp.go b/stytch/b2c/otp/whatsapp/whatsapp.go index 54800ab..80a8f10 100644 --- a/stytch/b2c/otp/whatsapp/whatsapp.go +++ b/stytch/b2c/otp/whatsapp/whatsapp.go @@ -4,10 +4,10 @@ import ( "context" "encoding/json" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v8/stytch/b2c" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) type Client struct { diff --git a/stytch/b2c/password/email/email.go b/stytch/b2c/password/email/email.go index 8d73940..9fa3989 100644 --- a/stytch/b2c/password/email/email.go +++ b/stytch/b2c/password/email/email.go @@ -5,10 +5,10 @@ import ( "encoding/json" "fmt" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v8/stytch/b2c" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) type Client struct { diff --git a/stytch/b2c/password/existingpassword/existingpassword.go b/stytch/b2c/password/existingpassword/existingpassword.go index a1f3fad..ad4410a 100644 --- a/stytch/b2c/password/existingpassword/existingpassword.go +++ b/stytch/b2c/password/existingpassword/existingpassword.go @@ -5,10 +5,10 @@ import ( "encoding/json" "fmt" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v8/stytch/b2c" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) type Client struct { diff --git a/stytch/b2c/password/password.go b/stytch/b2c/password/password.go index 6df88d4..d3ff80d 100644 --- a/stytch/b2c/password/password.go +++ b/stytch/b2c/password/password.go @@ -5,13 +5,13 @@ import ( "encoding/json" "fmt" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/password/email" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/password/existingpassword" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/password/session" + "github.com/stytchauth/stytch-go/v8/stytch/b2c" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/password/email" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/password/existingpassword" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/password/session" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) type Client struct { diff --git a/stytch/b2c/password/session/session.go b/stytch/b2c/password/session/session.go index f307981..95d558d 100644 --- a/stytch/b2c/password/session/session.go +++ b/stytch/b2c/password/session/session.go @@ -4,10 +4,10 @@ import ( "context" "encoding/json" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v8/stytch/b2c" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) type Client struct { diff --git a/stytch/b2c/session/session.go b/stytch/b2c/session/session.go index c4a4887..ab8630d 100644 --- a/stytch/b2c/session/session.go +++ b/stytch/b2c/session/session.go @@ -7,12 +7,12 @@ import ( "fmt" "time" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v8/stytch/b2c" "github.com/MicahParks/keyfunc" "github.com/golang-jwt/jwt/v4" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) var ErrJWTTooOld = errors.New("JWT too old") diff --git a/stytch/b2c/session/session_test.go b/stytch/b2c/session/session_test.go index c85d46c..00e8322 100644 --- a/stytch/b2c/session/session_test.go +++ b/stytch/b2c/session/session_test.go @@ -11,16 +11,16 @@ import ( "testing" "time" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/session" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/stytchapi" + "github.com/stytchauth/stytch-go/v8/stytch/b2c" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/session" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/stytchapi" "github.com/MicahParks/keyfunc" "github.com/golang-jwt/jwt/v4" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/config" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/config" ) func TestAuthenticateJWTLocal(t *testing.T) { diff --git a/stytch/b2c/stytchapi/stytchapi.go b/stytch/b2c/stytchapi/stytchapi.go index 19296c2..d44f285 100644 --- a/stytch/b2c/stytchapi/stytchapi.go +++ b/stytch/b2c/stytchapi/stytchapi.go @@ -5,26 +5,26 @@ import ( "fmt" "time" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/cryptowallet" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/magiclink" - mle "github.com/stytchauth/stytch-go/v7/stytch/b2c/magiclink/email" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/oauth" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/otp" - otpe "github.com/stytchauth/stytch-go/v7/stytch/b2c/otp/email" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/otp/sms" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/otp/whatsapp" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/password" - pe "github.com/stytchauth/stytch-go/v7/stytch/b2c/password/email" - pep "github.com/stytchauth/stytch-go/v7/stytch/b2c/password/existingpassword" - ps "github.com/stytchauth/stytch-go/v7/stytch/b2c/password/session" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/session" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/totp" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/user" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/webauthn" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/cryptowallet" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/magiclink" + mle "github.com/stytchauth/stytch-go/v8/stytch/b2c/magiclink/email" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/oauth" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/otp" + otpe "github.com/stytchauth/stytch-go/v8/stytch/b2c/otp/email" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/otp/sms" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/otp/whatsapp" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/password" + pe "github.com/stytchauth/stytch-go/v8/stytch/b2c/password/email" + pep "github.com/stytchauth/stytch-go/v8/stytch/b2c/password/existingpassword" + ps "github.com/stytchauth/stytch-go/v8/stytch/b2c/password/session" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/session" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/totp" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/user" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/webauthn" "github.com/MicahParks/keyfunc" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/config" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/config" ) type Logger interface { diff --git a/stytch/b2c/stytchapi/stytchapi_test.go b/stytch/b2c/stytchapi/stytchapi_test.go index e6d7113..34d252d 100644 --- a/stytch/b2c/stytchapi/stytchapi_test.go +++ b/stytch/b2c/stytchapi/stytchapi_test.go @@ -7,12 +7,12 @@ import ( "strings" "testing" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" - "github.com/stytchauth/stytch-go/v7/stytch/b2c/stytchapi" + "github.com/stytchauth/stytch-go/v8/stytch/b2c" + "github.com/stytchauth/stytch-go/v8/stytch/b2c/stytchapi" "github.com/stretchr/testify/assert" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/config" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/config" ) func TestNewClient(t *testing.T) { diff --git a/stytch/b2c/totp/totp.go b/stytch/b2c/totp/totp.go index b13dc0a..1fe4239 100644 --- a/stytch/b2c/totp/totp.go +++ b/stytch/b2c/totp/totp.go @@ -5,10 +5,10 @@ import ( "encoding/json" "fmt" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v8/stytch/b2c" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) type Client struct { diff --git a/stytch/b2c/user/user.go b/stytch/b2c/user/user.go index a7e651e..ab0cb59 100644 --- a/stytch/b2c/user/user.go +++ b/stytch/b2c/user/user.go @@ -5,10 +5,10 @@ import ( "encoding/json" "strconv" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v8/stytch/b2c" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) type Client struct { diff --git a/stytch/b2c/webauthn/webauthn.go b/stytch/b2c/webauthn/webauthn.go index 4315783..5d8f4f5 100644 --- a/stytch/b2c/webauthn/webauthn.go +++ b/stytch/b2c/webauthn/webauthn.go @@ -5,10 +5,10 @@ import ( "encoding/json" "fmt" - "github.com/stytchauth/stytch-go/v7/stytch/b2c" + "github.com/stytchauth/stytch-go/v8/stytch/b2c" - "github.com/stytchauth/stytch-go/v7/stytch" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) type Client struct { diff --git a/stytch/config/config.go b/stytch/config/config.go index ce6df3f..e70d6d7 100644 --- a/stytch/config/config.go +++ b/stytch/config/config.go @@ -1,6 +1,6 @@ package config -const APIVersion = "7.1.3" +const APIVersion = "8.0.0" type BaseURI string diff --git a/stytch/stytch.go b/stytch/stytch.go index cbc1ebc..e91751f 100644 --- a/stytch/stytch.go +++ b/stytch/stytch.go @@ -10,8 +10,8 @@ import ( "net/http" "strings" - "github.com/stytchauth/stytch-go/v7/stytch/config" - "github.com/stytchauth/stytch-go/v7/stytch/stytcherror" + "github.com/stytchauth/stytch-go/v8/stytch/config" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" ) const ( diff --git a/stytch/stytcherror/stytcherror.go b/stytch/stytcherror/stytcherror.go index da0784c..87f8f80 100644 --- a/stytch/stytcherror/stytcherror.go +++ b/stytch/stytcherror/stytcherror.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/stytchauth/stytch-go/v7/stytch/config" + "github.com/stytchauth/stytch-go/v8/stytch/config" ) type Error struct { From 568b349e062932e03b866037026d6a612935567b Mon Sep 17 00:00:00 2001 From: Max Gerber <89937743+max-stytch@users.noreply.github.com> Date: Mon, 1 May 2023 15:43:42 -0700 Subject: [PATCH 10/12] B2B SSO Support (#116) --- stytch/b2b/b2bstytchapi/b2bstytchapi.go | 5 + stytch/b2b/sso.go | 131 ++++++++++++++++++++++++ stytch/b2b/sso/oidc/oidc.go | 61 +++++++++++ stytch/b2b/sso/saml/saml.go | 74 +++++++++++++ stytch/b2b/sso/sso.go | 63 ++++++++++++ 5 files changed, 334 insertions(+) create mode 100644 stytch/b2b/sso.go create mode 100644 stytch/b2b/sso/oidc/oidc.go create mode 100644 stytch/b2b/sso/saml/saml.go create mode 100644 stytch/b2b/sso/sso.go diff --git a/stytch/b2b/b2bstytchapi/b2bstytchapi.go b/stytch/b2b/b2bstytchapi/b2bstytchapi.go index 9ac3dd0..3324d19 100644 --- a/stytch/b2b/b2bstytchapi/b2bstytchapi.go +++ b/stytch/b2b/b2bstytchapi/b2bstytchapi.go @@ -7,6 +7,9 @@ import ( mle "github.com/stytchauth/stytch-go/v8/stytch/b2b/magiclink/email" "github.com/stytchauth/stytch-go/v8/stytch/b2b/organization" "github.com/stytchauth/stytch-go/v8/stytch/b2b/session" + "github.com/stytchauth/stytch-go/v8/stytch/b2b/sso" + "github.com/stytchauth/stytch-go/v8/stytch/b2b/sso/oidc" + "github.com/stytchauth/stytch-go/v8/stytch/b2b/sso/saml" "github.com/stytchauth/stytch-go/v8/stytch/config" ) @@ -21,6 +24,7 @@ type API struct { Organization *organization.Client Session *session.Client Discovery *discovery.Client + SSO *sso.Client } type Option func(*API) @@ -50,5 +54,6 @@ func NewAPIClient(env config.Env, projectID string, secret string, opts ...Optio a.Organization = &organization.Client{C: a.client} a.Session = &session.Client{C: a.client} a.Discovery = &discovery.Client{C: a.client} + a.SSO = &sso.Client{C: a.client, OIDC: &oidc.Client{C: a.client}, SAML: &saml.Client{C: a.client}} return a, nil } diff --git a/stytch/b2b/sso.go b/stytch/b2b/sso.go new file mode 100644 index 0000000..bdd3417 --- /dev/null +++ b/stytch/b2b/sso.go @@ -0,0 +1,131 @@ +package b2b + +type X509Certificate struct { + CertificateID string `json:"certificate_id,omitempty"` + Certificate string `json:"certificate,omitempty"` + Issuer string `json:"issuer,omitempty"` + CreatedAt string `json:"created_at,omitempty"` + ExpiresAt string `json:"expires_at,omitempty"` +} + +type OIDCConnection struct { + OrganizationID string `json:"organization_id,omitempty"` + ConnectionID string `json:"connection_id,omitempty"` + Status string `json:"status,omitempty"` + DisplayName string `json:"display_name,omitempty"` + RedirectURL string `json:"redirect_url,omitempty"` + ClientID string `json:"client_id,omitempty"` + ClientSecret string `json:"client_secret,omitempty"` + Issuer string `json:"issuer,omitempty"` + AuthorizationURL string `json:"authorization_url,omitempty"` + TokenURL string `json:"token_url,omitempty"` + UserinfoURL string `json:"userinfo_url,omitempty"` + JwksURL string `json:"jwks_url,omitempty"` +} + +type SAMLConnection struct { + OrganizationID string `json:"organization_id,omitempty"` + ConnectionID string `json:"connection_id,omitempty"` + Status string `json:"status,omitempty"` + AttributeMapping map[string]string `json:"attribute_mapping,omitempty"` + IdpEntityID string `json:"idp_entity_id,omitempty"` + DisplayName string `json:"display_name,omitempty"` + IdpSsoURL string `json:"idp_sso_url,omitempty"` + AcsURL string `json:"acs_url,omitempty"` + AudienceURI string `json:"audience_uri,omitempty"` + SigningCertificates []X509Certificate `json:"signing_certificates,omitempty"` + VerificationCertificates []X509Certificate `json:"verification_certificates,omitempty"` +} + +type SSOGetConnectionsResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + SAMLConnections []SAMLConnection `json:"saml_connections,omitempty"` + OIDCConnections []OIDCConnection `json:"oidc_connections,omitempty"` +} + +type SSODeleteConnectionResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + ConnectionID string `json:"connection_id,omitempty"` +} + +type SSOAuthenticateParams struct { + SSOToken string `json:"sso_token,omitempty"` + SessionToken string `json:"session_token,omitempty"` + SessionDurationMinutes int32 `json:"session_duration_minutes,omitempty"` + SessionJWT string `json:"session_jwt,omitempty"` + SessionCustomClaims map[string]interface{} `json:"session_custom_claims,omitempty"` + PKCECodeVerifier string `json:"pkce_code_verifier,omitempty"` +} + +type SSOAuthenticateResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + MemberID string `json:"member_id,omitempty"` + MethodID string `json:"method_id,omitempty"` + ResetSessions bool `json:"reset_sessions,omitempty"` + OrganizationID string `json:"organization_id,omitempty"` + Member Member `json:"member,omitempty"` + SessionToken string `json:"session_token,omitempty"` + SessionJWT string `json:"session_jwt,omitempty"` + MemberSession MemberSession `json:"member_session,omitempty"` + Organization Organization `json:"organization,omitempty"` +} + +type OIDCCreateConnectionParams struct { + DisplayName string `json:"display_name,omitempty"` +} + +type OIDCCreateConnectionResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + Connection OIDCConnection `json:"connection,omitempty"` +} + +type OIDCUpdateConnectionParams struct { + DisplayName string `json:"display_name,omitempty"` + ClientID string `json:"client_id,omitempty"` + ClientSecret string `json:"client_secret,omitempty"` + Issuer string `json:"issuer,omitempty"` + AuthorizationURL string `json:"authorization_url,omitempty"` + TokenURL string `json:"token_url,omitempty"` + UserinfoURL string `json:"userinfo_url,omitempty"` + JwksURL string `json:"jwks_url,omitempty"` +} + +type OIDCUpdateConnectionResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + Connection OIDCConnection `json:"connection,omitempty"` +} + +type SAMLCreateConnectionParams struct { + DisplayName string `json:"display_name,omitempty"` +} + +type SAMLCreateConnectionResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + Connection SAMLConnection `json:"connection,omitempty"` +} + +type SAMLUpdateConnectionParams struct { + IdpEntityID string `json:"idp_entity_id,omitempty"` + DisplayName string `json:"display_name,omitempty"` + AttributeMapping map[string]string `json:"attribute_mapping,omitempty"` + X509Certificate string `json:"x509_certificate,omitempty"` + IdpSsoURL string `json:"idp_sso_url,omitempty"` +} + +type SAMLUpdateConnectionResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + Connection SAMLConnection `json:"connection,omitempty"` +} + +type SAMLDeleteVerificationCertificateResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + CertificateID string `json:"certificate_id,omitempty"` +} diff --git a/stytch/b2b/sso/oidc/oidc.go b/stytch/b2b/sso/oidc/oidc.go new file mode 100644 index 0000000..3cf12da --- /dev/null +++ b/stytch/b2b/sso/oidc/oidc.go @@ -0,0 +1,61 @@ +package oidc + +import ( + "context" + "encoding/json" + + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/b2b" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" +) + +type Client struct { + C *stytch.Client +} + +func (c *Client) Create( + ctx context.Context, + organizationID string, + body *b2b.OIDCCreateConnectionParams, +) (*b2b.OIDCCreateConnectionResponse, error) { + path := "/b2b/sso/oidc/" + organizationID + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the OIDC Create request body") + } + } + + var retVal b2b.OIDCCreateConnectionResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} + +func (c *Client) Update( + ctx context.Context, + organizationID string, + connectionID string, + body *b2b.OIDCUpdateConnectionParams, +) (*b2b.OIDCUpdateConnectionResponse, error) { + path := "/b2b/sso/oidc/" + organizationID + "/connections/" + connectionID + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the OIDC Update request body") + } + } + + var retVal b2b.OIDCUpdateConnectionResponse + err = c.C.NewRequest(ctx, "PUT", path, nil, jsonBody, &retVal) + return &retVal, err +} diff --git a/stytch/b2b/sso/saml/saml.go b/stytch/b2b/sso/saml/saml.go new file mode 100644 index 0000000..090f369 --- /dev/null +++ b/stytch/b2b/sso/saml/saml.go @@ -0,0 +1,74 @@ +package saml + +import ( + "context" + "encoding/json" + + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/b2b" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" +) + +type Client struct { + C *stytch.Client +} + +func (c *Client) Create( + ctx context.Context, + organizationID string, + body *b2b.SAMLCreateConnectionParams, +) (*b2b.SAMLCreateConnectionResponse, error) { + path := "/b2b/sso/saml/" + organizationID + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the SAML Create request body") + } + } + + var retVal b2b.SAMLCreateConnectionResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} + +func (c *Client) Update( + ctx context.Context, + organizationID string, + connectionID string, + body *b2b.SAMLUpdateConnectionParams, +) (*b2b.SAMLUpdateConnectionResponse, error) { + path := "/b2b/sso/saml/" + organizationID + "/connections/" + connectionID + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the SAML Update request body") + } + } + + var retVal b2b.SAMLUpdateConnectionResponse + err = c.C.NewRequest(ctx, "PUT", path, nil, jsonBody, &retVal) + return &retVal, err +} + +func (c *Client) DeleteVerificationCertificate( + ctx context.Context, + organizationID string, + connectionID string, + certificateID string, +) (*b2b.SAMLDeleteVerificationCertificateResponse, error) { + path := "/b2b/sso/saml/" + organizationID + "/connections/" + connectionID + "/verification_certificates/" + certificateID + + var retVal b2b.SAMLDeleteVerificationCertificateResponse + err := c.C.NewRequest(ctx, "DELETE", path, nil, nil, &retVal) + return &retVal, err +} diff --git a/stytch/b2b/sso/sso.go b/stytch/b2b/sso/sso.go new file mode 100644 index 0000000..ac114dd --- /dev/null +++ b/stytch/b2b/sso/sso.go @@ -0,0 +1,63 @@ +package sso + +import ( + "context" + "encoding/json" + + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/b2b" + "github.com/stytchauth/stytch-go/v8/stytch/b2b/sso/oidc" + "github.com/stytchauth/stytch-go/v8/stytch/b2b/sso/saml" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" +) + +type Client struct { + C *stytch.Client + SAML *saml.Client + OIDC *oidc.Client +} + +func (c *Client) Get( + ctx context.Context, + organizationID string, +) (*b2b.SSOGetConnectionsResponse, error) { + path := "/b2b/sso/" + organizationID + + var retVal b2b.SSOGetConnectionsResponse + err := c.C.NewRequest(ctx, "GET", path, nil, nil, &retVal) + return &retVal, err +} + +func (c *Client) Authenticate( + ctx context.Context, + body *b2b.SSOAuthenticateParams, +) (*b2b.SSOAuthenticateResponse, error) { + path := "/b2b/sso/authenticate" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the /b2b/sso/authenticate request body") + } + } + + var retVal b2b.SSOAuthenticateResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} + +func (c *Client) Delete( + ctx context.Context, + organizationID string, + connectionID string, +) (*b2b.SSODeleteConnectionResponse, error) { + path := "/b2b/sso/" + organizationID + "/connections/" + connectionID + + var retVal b2b.SSODeleteConnectionResponse + err := c.C.NewRequest(ctx, "DELETE", path, nil, nil, &retVal) + return &retVal, err +} From 8cb6c951374fb3dd93039c1fee12f4a15bf225e4 Mon Sep 17 00:00:00 2001 From: Max Gerber <89937743+max-stytch@users.noreply.github.com> Date: Mon, 1 May 2023 15:43:59 -0700 Subject: [PATCH 11/12] B2B Passwords Support (#117) --- stytch/b2b/b2bstytchapi/b2bstytchapi.go | 11 ++ stytch/b2b/password.go | 158 ++++++++++++++++++ stytch/b2b/password/email/email.go | 59 +++++++ .../existingpassword/existingpassword.go | 37 ++++ stytch/b2b/password/password.go | 87 ++++++++++ stytch/b2b/password/session/session.go | 37 ++++ stytch/b2c/password.go | 50 +----- stytch/shared/password.go | 39 +++++ 8 files changed, 435 insertions(+), 43 deletions(-) create mode 100644 stytch/b2b/password.go create mode 100644 stytch/b2b/password/email/email.go create mode 100644 stytch/b2b/password/existingpassword/existingpassword.go create mode 100644 stytch/b2b/password/password.go create mode 100644 stytch/b2b/password/session/session.go create mode 100644 stytch/shared/password.go diff --git a/stytch/b2b/b2bstytchapi/b2bstytchapi.go b/stytch/b2b/b2bstytchapi/b2bstytchapi.go index 3324d19..27aacb1 100644 --- a/stytch/b2b/b2bstytchapi/b2bstytchapi.go +++ b/stytch/b2b/b2bstytchapi/b2bstytchapi.go @@ -6,6 +6,10 @@ import ( "github.com/stytchauth/stytch-go/v8/stytch/b2b/magiclink" mle "github.com/stytchauth/stytch-go/v8/stytch/b2b/magiclink/email" "github.com/stytchauth/stytch-go/v8/stytch/b2b/organization" + "github.com/stytchauth/stytch-go/v8/stytch/b2b/password" + pe "github.com/stytchauth/stytch-go/v8/stytch/b2b/password/email" + pep "github.com/stytchauth/stytch-go/v8/stytch/b2b/password/existingpassword" + ps "github.com/stytchauth/stytch-go/v8/stytch/b2b/password/session" "github.com/stytchauth/stytch-go/v8/stytch/b2b/session" "github.com/stytchauth/stytch-go/v8/stytch/b2b/sso" "github.com/stytchauth/stytch-go/v8/stytch/b2b/sso/oidc" @@ -23,6 +27,7 @@ type API struct { MagicLinks *magiclink.Client Organization *organization.Client Session *session.Client + Passwords *password.Client Discovery *discovery.Client SSO *sso.Client } @@ -53,6 +58,12 @@ func NewAPIClient(env config.Env, projectID string, secret string, opts ...Optio a.MagicLinks = &magiclink.Client{C: a.client, Email: &mle.Client{C: a.client}} a.Organization = &organization.Client{C: a.client} a.Session = &session.Client{C: a.client} + a.Passwords = &password.Client{ + C: a.client, + Email: &pe.Client{C: a.client}, + Session: &ps.Client{C: a.client}, + ExistingPassword: &pep.Client{C: a.client}, + } a.Discovery = &discovery.Client{C: a.client} a.SSO = &sso.Client{C: a.client, OIDC: &oidc.Client{C: a.client}, SAML: &saml.Client{C: a.client}} return a, nil diff --git a/stytch/b2b/password.go b/stytch/b2b/password.go new file mode 100644 index 0000000..f9cb608 --- /dev/null +++ b/stytch/b2b/password.go @@ -0,0 +1,158 @@ +package b2b + +import "github.com/stytchauth/stytch-go/v8/stytch/shared" + +type PasswordsAuthenticateParams struct { + EmailAddress string `json:"email_address"` + Password string `json:"password"` + SessionToken string `json:"session_token,omitempty"` + SessionJWT string `json:"session_jwt,omitempty"` + SessionDurationMinutes int32 `json:"session_duration_minutes,omitempty"` + SessionCustomClaims map[string]interface{} `json:"session_custom_claims,omitempty"` +} + +type PasswordsAuthenticateResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + MemberID string `json:"member_id,omitempty"` + OrganizationID string `json:"organization_id,omitempty"` + Member Member `json:"member,omitempty"` + SessionToken string `json:"session_token,omitempty"` + SessionJWT string `json:"session_jwt,omitempty"` + MemberSession MemberSession `json:"member_session,omitempty"` + Organization Organization `json:"organization,omitempty"` +} + +type PasswordsStrengthCheckParams struct { + EmailAddress string `json:"email_address"` + Password string `json:"password"` +} + +type PasswordsStrengthCheckResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + ValidPassword bool `json:"valid_password,omitempty"` + Score int `json:"score,omitempty"` + BreachedPassword bool `json:"breached_password,omitempty"` + ZXCVBNFeedback ZXCVBNFeedback `json:"zxcvbn_feedback,omitempty"` + LUDSFeedback LUDSFeedback `json:"luds_feedback,omitempty"` + StrengthPolicy string `json:"strength_policy,omitempty"` + BreachDetectionOnCreate bool `json:"breach_detection_on_create,omitempty"` +} + +type ZXCVBNFeedback struct { + Warning string `json:"warning,omitempty"` + Suggestions []string `json:"suggestions,omitempty"` +} + +type LUDSFeedback struct { + HasLowerCase bool `json:"has_lower_case,omitempty"` + HasUpperCase bool `json:"has_upper_case,omitempty"` + HasDigit bool `json:"has_digit,omitempty"` + HasSymbol bool `json:"has_symbol,omitempty"` + MissingComplexity int `json:"missing_complexity,omitempty"` + MissingCharacters int `json:"missing_characters,omitempty"` +} + +type PasswordsMigrateParams struct { + OrganizationID string `json:"organization_id"` + EmailAddress string `json:"email_address"` + TrustedMetadata map[string]interface{} `json:"trusted_metadata,omitempty"` + UntrustedMetadata map[string]interface{} `json:"untrusted_metadata,omitempty"` + Hash string `json:"hash"` + HashType shared.HashType `json:"hash_type"` + MD5Config shared.MD5Config `json:"md_5_config,omitempty"` + Argon2Config shared.Argon2Config `json:"argon_2_config,omitempty"` + SHA1Config shared.SHA1Config `json:"sha_1_config,omitempty"` + ScryptConfig shared.ScryptConfig `json:"scrypt_config,omitempty"` +} + +type PasswordsMigrateResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + UserID string `json:"user_id,omitempty"` + EmailID string `json:"email_id,omitempty"` + UserCreated bool `json:"user_created,omitempty"` +} + +// PASSWORD - EMAIL +type PasswordEmailResetStartParams struct { + OrganizationID string `json:"organization_id"` + EmailAddress string `json:"email_address"` + LoginRedirectURL string `json:"login_redirect_url,omitempty"` + ResetPasswordRedirectURL string `json:"reset_password_redirect_url,omitempty"` + ResetPasswordExpirationMinutes int32 `json:"reset_password_expiration_minutes,omitempty"` + ResetPasswordTemplateID string `json:"reset_password_template_id,omitempty"` + CodeChallenge string `json:"code_challenge,omitempty"` + Locale string `json:"locale,omitempty"` +} + +type PasswordEmailResetStartResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + MemberID string `json:"user_id,omitempty"` + MemberEmailID string `json:"email_id,omitempty"` +} + +type PasswordEmailResetParams struct { + PasswordResetToken string `json:"password_reset_token"` + Password string `json:"password"` + SessionToken string `json:"session_token,omitempty"` + SessionJWT string `json:"session_jwt,omitempty"` + SessionDurationMinutes int32 `json:"session_duration_minutes,omitempty"` + SessionCustomClaims map[string]interface{} `json:"session_custom_claims,omitempty"` + CodeVerifier string `json:"code_verifier,omitempty"` +} + +type PasswordEmailResetResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + MemberID string `json:"member_id,omitempty"` + OrganizationID string `json:"organization_id,omitempty"` + Member Member `json:"member,omitempty"` + SessionToken string `json:"session_token,omitempty"` + SessionJWT string `json:"session_jwt,omitempty"` + MemberSession MemberSession `json:"member_session,omitempty"` + Organization Organization `json:"organization,omitempty"` +} + +// PASSWORD - EXISTING PASSWORD +type PasswordExistingPasswordResetParams struct { + OrganizationID string `json:"organization_id"` + EmailAddress string `json:"email_address"` + ExistingPassword string `json:"existing_password"` + NewPassword string `json:"new_password"` + SessionToken string `json:"session_token,omitempty"` + SessionJWT string `json:"session_jwt,omitempty"` + SessionDurationMinutes int32 `json:"session_duration_minutes,omitempty"` + SessionCustomClaims map[string]interface{} `json:"session_custom_claims,omitempty"` +} + +type PasswordExistingPasswordResetResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + MemberID string `json:"member_id,omitempty"` + OrganizationID string `json:"organization_id,omitempty"` + Member Member `json:"member,omitempty"` + SessionToken string `json:"session_token,omitempty"` + SessionJWT string `json:"session_jwt,omitempty"` + MemberSession MemberSession `json:"member_session,omitempty"` + Organization Organization `json:"organization,omitempty"` +} + +// PASSWORD - SESSION +type PasswordSessionResetParams struct { + OrganizationID string `json:"organization_id"` + Password string `json:"password"` + SessionToken string `json:"session_token,omitempty"` + SessionJWT string `json:"session_jwt,omitempty"` +} + +type PasswordSessionResetResponse struct { + RequestID string `json:"request_id,omitempty"` + StatusCode int `json:"status_code,omitempty"` + MemberID string `json:"member_id,omitempty"` + Member Member `json:"member,omitempty"` + MemberSession MemberSession `json:"member_session,omitempty"` + Organization Organization `json:"organization,omitempty"` +} diff --git a/stytch/b2b/password/email/email.go b/stytch/b2b/password/email/email.go new file mode 100644 index 0000000..376de97 --- /dev/null +++ b/stytch/b2b/password/email/email.go @@ -0,0 +1,59 @@ +package email + +import ( + "context" + "encoding/json" + + "github.com/stytchauth/stytch-go/v8/stytch/b2b" + + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" +) + +type Client struct { + C *stytch.Client +} + +func (c *Client) ResetStart( + ctx context.Context, + body *b2b.PasswordEmailResetStartParams, +) (*b2b.PasswordEmailResetStartResponse, error) { + path := "/b2b/passwords/email/reset/start" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the /b2b/passwords/email/reset/start request body") + } + } + + var retVal b2b.PasswordEmailResetStartResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} + +func (c *Client) Reset( + ctx context.Context, + body *b2b.PasswordEmailResetParams, +) (*b2b.PasswordEmailResetResponse, error) { + path := "/b2b/passwords/email/reset" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the /b2b/passwords/email/reset request body") + } + } + + var retVal b2b.PasswordEmailResetResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} diff --git a/stytch/b2b/password/existingpassword/existingpassword.go b/stytch/b2b/password/existingpassword/existingpassword.go new file mode 100644 index 0000000..c69d10b --- /dev/null +++ b/stytch/b2b/password/existingpassword/existingpassword.go @@ -0,0 +1,37 @@ +package existingpassword + +import ( + "context" + "encoding/json" + + "github.com/stytchauth/stytch-go/v8/stytch/b2b" + + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" +) + +type Client struct { + C *stytch.Client +} + +func (c *Client) Reset( + ctx context.Context, + body *b2b.PasswordExistingPasswordResetParams, +) (*b2b.PasswordExistingPasswordResetResponse, error) { + path := "/b2b/passwords/existing_password/reset" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the /b2b/passwords/existing_password/reset request body") + } + } + + var retVal b2b.PasswordExistingPasswordResetResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} diff --git a/stytch/b2b/password/password.go b/stytch/b2b/password/password.go new file mode 100644 index 0000000..9123b45 --- /dev/null +++ b/stytch/b2b/password/password.go @@ -0,0 +1,87 @@ +package password + +import ( + "context" + "encoding/json" + + "github.com/stytchauth/stytch-go/v8/stytch/b2b" + "github.com/stytchauth/stytch-go/v8/stytch/b2b/password/email" + "github.com/stytchauth/stytch-go/v8/stytch/b2b/password/existingpassword" + "github.com/stytchauth/stytch-go/v8/stytch/b2b/password/session" + + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" +) + +type Client struct { + C *stytch.Client + Email *email.Client + ExistingPassword *existingpassword.Client + Session *session.Client +} + +func (c *Client) Authenticate( + ctx context.Context, + body *b2b.PasswordsAuthenticateParams, +) (*b2b.PasswordsAuthenticateResponse, error) { + path := "/b2b/passwords/authenticate" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the /b2b/passwords/authenticate request body") + } + } + + var retVal b2b.PasswordsAuthenticateResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} + +func (c *Client) StrengthCheck( + ctx context.Context, + body *b2b.PasswordsStrengthCheckParams, +) (*b2b.PasswordsStrengthCheckResponse, error) { + path := "/b2b/passwords/strength_check" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the /b2b/passwords/strength_check request body") + } + } + + var retVal b2b.PasswordsStrengthCheckResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} + +func (c *Client) Migrate( + ctx context.Context, + body *b2b.PasswordsMigrateParams, +) (*b2b.PasswordsMigrateResponse, error) { + path := "/b2b/passwords/migrate" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the /b2b/passwords/migrate request body") + } + } + + var retVal b2b.PasswordsMigrateResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} diff --git a/stytch/b2b/password/session/session.go b/stytch/b2b/password/session/session.go new file mode 100644 index 0000000..3b73a0d --- /dev/null +++ b/stytch/b2b/password/session/session.go @@ -0,0 +1,37 @@ +package session + +import ( + "context" + "encoding/json" + + "github.com/stytchauth/stytch-go/v8/stytch/b2b" + + "github.com/stytchauth/stytch-go/v8/stytch" + "github.com/stytchauth/stytch-go/v8/stytch/stytcherror" +) + +type Client struct { + C *stytch.Client +} + +func (c *Client) Reset( + ctx context.Context, + body *b2b.PasswordSessionResetParams, +) (*b2b.PasswordSessionResetResponse, error) { + path := "/b2b/passwords/session/reset" + + var jsonBody []byte + var err error + if body != nil { + jsonBody, err = json.Marshal(body) + if err != nil { + return nil, stytcherror.NewClientLibraryError( + "Oops, something seems to have gone wrong " + + "marshalling the /b2b/passwords/session/reset request body") + } + } + + var retVal b2b.PasswordSessionResetResponse + err = c.C.NewRequest(ctx, "POST", path, nil, jsonBody, &retVal) + return &retVal, err +} diff --git a/stytch/b2c/password.go b/stytch/b2c/password.go index 3c28f5c..de0563a 100644 --- a/stytch/b2c/password.go +++ b/stytch/b2c/password.go @@ -1,5 +1,7 @@ package b2c +import "github.com/stytchauth/stytch-go/v8/stytch/shared" + type PasswordsCreateParams struct { Email string `json:"email"` Password string `json:"password"` @@ -77,37 +79,11 @@ type PasswordsMigrateParams struct { TrustedMetadata map[string]interface{} `json:"trusted_metadata,omitempty"` UntrustedMetadata map[string]interface{} `json:"untrusted_metadata,omitempty"` Hash string `json:"hash"` - HashType HashType `json:"hash_type"` - MD5Config MD5Config `json:"md_5_config,omitempty"` - Argon2Config Argon2Config `json:"argon_2_config,omitempty"` - SHA1Config SHA1Config `json:"sha_1_config,omitempty"` - ScryptConfig ScryptConfig `json:"scrypt_config,omitempty"` -} - -type MD5Config struct { - PrependSalt string `json:"prepend_salt,omitempty"` - AppendSalt string `json:"append_salt,omitempty"` -} - -type Argon2Config struct { - Salt string `json:"salt"` - IterationAmount int `json:"iteration_amount"` - Memory int `json:"memory"` - Threads int `json:"threads"` - KeyLength int `json:"key_length"` -} - -type SHA1Config struct { - PrependSalt string `json:"prepend_salt,omitempty"` - AppendSalt string `json:"append_salt,omitempty"` -} - -type ScryptConfig struct { - Salt string `json:"salt"` - NParameter int `json:"n_parameter"` - RParameter int `json:"r_parameter"` - PParameter int `json:"p_parameter"` - KeyLength int `json:"key_length"` + HashType shared.HashType `json:"hash_type"` + MD5Config shared.MD5Config `json:"md_5_config,omitempty"` + Argon2Config shared.Argon2Config `json:"argon_2_config,omitempty"` + SHA1Config shared.SHA1Config `json:"sha_1_config,omitempty"` + ScryptConfig shared.ScryptConfig `json:"scrypt_config,omitempty"` } type PasswordsMigrateResponse struct { @@ -118,18 +94,6 @@ type PasswordsMigrateResponse struct { UserCreated bool `json:"user_created,omitempty"` } -type HashType string - -const ( - HashTypeBcrypt HashType = "bcrypt" - HashTypeMD5 HashType = "md_5" - HashTypeArgon2I HashType = "argon_2i" - HashTypeArgon2ID HashType = "argon_2id" - HashTypeSHA1 HashType = "sha_1" - HashTypeScrypt HashType = "scrypt" - HashTypePHPass HashType = "phpass" -) - // PASSWORD - EMAIL type PasswordEmailResetStartParams struct { Email string `json:"email"` diff --git a/stytch/shared/password.go b/stytch/shared/password.go new file mode 100644 index 0000000..64b9b16 --- /dev/null +++ b/stytch/shared/password.go @@ -0,0 +1,39 @@ +package shared + +type MD5Config struct { + PrependSalt string `json:"prepend_salt,omitempty"` + AppendSalt string `json:"append_salt,omitempty"` +} + +type Argon2Config struct { + Salt string `json:"salt"` + IterationAmount int `json:"iteration_amount"` + Memory int `json:"memory"` + Threads int `json:"threads"` + KeyLength int `json:"key_length"` +} + +type SHA1Config struct { + PrependSalt string `json:"prepend_salt,omitempty"` + AppendSalt string `json:"append_salt,omitempty"` +} + +type ScryptConfig struct { + Salt string `json:"salt"` + NParameter int `json:"n_parameter"` + RParameter int `json:"r_parameter"` + PParameter int `json:"p_parameter"` + KeyLength int `json:"key_length"` +} + +type HashType string + +const ( + HashTypeBcrypt HashType = "bcrypt" + HashTypeMD5 HashType = "md_5" + HashTypeArgon2I HashType = "argon_2i" + HashTypeArgon2ID HashType = "argon_2id" + HashTypeSHA1 HashType = "sha_1" + HashTypeScrypt HashType = "scrypt" + HashTypePHPass HashType = "phpass" +) From 2ba373f1d632861cd124e9c361492e8f1e56ebda Mon Sep 17 00:00:00 2001 From: alex-stytch Date: Tue, 2 May 2023 14:11:58 -0700 Subject: [PATCH 12/12] Add search queries --- stytch/b2b/organization.go | 159 ++++++++++++++++++++++++++++++++++++- 1 file changed, 158 insertions(+), 1 deletion(-) diff --git a/stytch/b2b/organization.go b/stytch/b2b/organization.go index 53fe298..24b2b19 100644 --- a/stytch/b2b/organization.go +++ b/stytch/b2b/organization.go @@ -1,6 +1,8 @@ package b2b -import "encoding/json" +import ( + "encoding/json" +) type OrganizationCreateParams struct { OrganizationName string `json:"organization_name"` @@ -198,3 +200,158 @@ type MemberSearchQuery struct { Operator SearchOperator `json:"operator,omitempty"` Operands []json.Marshaler `json:"operands,omitempty"` } + +func marshalFilter(filterName string, filterValue interface{}) ([]byte, error) { + return json.Marshal(map[string]interface{}{ + "filter_name": filterName, + "filter_value": filterValue, + }) +} + +// Organization Search Filters + +type OrganizationSearchOrganizationIDsQuery struct { + OrganizationIDs []string +} + +func (q OrganizationSearchOrganizationIDsQuery) MarshalJSON() ([]byte, error) { + return marshalFilter("organization_ids", q.OrganizationIDs) +} + +type OrganizationSearchOrganizationSlugsQuery struct { + OrganizationSlugs []string +} + +func (q OrganizationSearchOrganizationSlugsQuery) MarshalJSON() ([]byte, error) { + return marshalFilter("organization_slugs", q.OrganizationSlugs) +} + +type OrganizationSearchOrganizationNameFuzzyQuery struct { + OrganizationNameFuzzy string +} + +func (q OrganizationSearchOrganizationNameFuzzyQuery) MarshalJSON() ([]byte, error) { + return marshalFilter("organization_name_fuzzy", q.OrganizationNameFuzzy) +} + +type OrganizationSearchOrganizationSlugFuzzyQuery struct { + OrganizationSlugFuzzy string +} + +func (q OrganizationSearchOrganizationSlugFuzzyQuery) MarshalJSON() ([]byte, error) { + return marshalFilter("organization_slug_fuzzy", q.OrganizationSlugFuzzy) +} + +type OrganizationSearchMemberEmailsQuery struct { + MemberEmails []string +} + +func (q OrganizationSearchMemberEmailsQuery) MarshalJSON() ([]byte, error) { + return marshalFilter("member_emails", q.MemberEmails) +} + +type OrganizationSearchMemberEmailFuzzyQuery struct { + MemberEmailFuzzy string +} + +func (q OrganizationSearchMemberEmailFuzzyQuery) MarshalJSON() ([]byte, error) { + return marshalFilter("member_email_fuzzy", q.MemberEmailFuzzy) +} + +type OrganizationSearchAllowedDomainsQuery struct { + AllowedDomains []string +} + +func (q OrganizationSearchAllowedDomainsQuery) MarshalJSON() ([]byte, error) { + return marshalFilter("allowed_domains", q.AllowedDomains) +} + +type OrganizationSearchAllowedDomainFuzzyQuery struct { + AllowedDomainFuzzy string +} + +func (q OrganizationSearchAllowedDomainFuzzyQuery) MarshalJSON() ([]byte, error) { + return marshalFilter("allowed_domain_fuzzy", q.AllowedDomainFuzzy) +} + +// Member Search Filters + +type MemberSearchMemberIDsQuery struct { + MemberIDs []string +} + +func (q MemberSearchMemberIDsQuery) MarshalJSON() ([]byte, error) { + return marshalFilter("member_ids", q.MemberIDs) +} + +type MemberSearchMemberEmailsQuery struct { + MemberEmails []string +} + +func (q MemberSearchMemberEmailsQuery) MarshalJSON() ([]byte, error) { + return marshalFilter("member_emails", q.MemberEmails) +} + +type MemberSearchMemberEmailFuzzyQuery struct { + MemberEmailFuzzy string +} + +func (q MemberSearchMemberEmailFuzzyQuery) MarshalJSON() ([]byte, error) { + return marshalFilter("member_email_fuzzy", q.MemberEmailFuzzy) +} + +type MemberSearchMemberIsBreakglassQuery struct { + MemberIsBreakglass bool +} + +func (q MemberSearchMemberIsBreakglassQuery) MarshalJSON() ([]byte, error) { + return marshalFilter("member_is_breakglass", q.MemberIsBreakglass) +} + +type MemberSearchMemberPasswordExistsQuery struct { + MemberPasswordExists bool +} + +func (q MemberSearchMemberPasswordExistsQuery) MarshalJSON() ([]byte, error) { + return marshalFilter("member_password_exists", q.MemberPasswordExists) +} + +type MemberSearchOrganizationIDQuery struct { + OrganizationID string +} + +func (q MemberSearchOrganizationIDQuery) MarshalJSON() ([]byte, error) { + return marshalFilter("organization_id", q.OrganizationID) +} + +type MemberSearchOrganizationSlugQuery struct { + OrganizationSlug string +} + +func (q MemberSearchOrganizationSlugQuery) MarshalJSON() ([]byte, error) { + return marshalFilter("organization_slug", q.OrganizationSlug) +} + +type MemberSearchOrganizationSlugFuzzyQuery struct { + OrganizationSlugFuzzy string +} + +func (q MemberSearchOrganizationSlugFuzzyQuery) MarshalJSON() ([]byte, error) { + return marshalFilter("organization_slug_fuzzy", q.OrganizationSlugFuzzy) +} + +type MemberSearchStatusQuery struct { + Status string +} + +func (q MemberSearchStatusQuery) MarshalJSON() ([]byte, error) { + return marshalFilter("status", q.Status) +} + +type MemberSearchStatusesQuery struct { + Statuses []string +} + +func (q MemberSearchStatusesQuery) MarshalJSON() ([]byte, error) { + return marshalFilter("statuses", q.Statuses) +}