Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for OAuth Attach endpoint #98

Merged
merged 3 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stytch/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package config

const APIVersion = "6.3.0"
const APIVersion = "6.4.0"

type BaseURI string

Expand Down
13 changes: 13 additions & 0 deletions stytch/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,16 @@ type ProviderValues struct {
ExpiresAt *time.Time `json:"expires_at,omitempty"`
Scopes []string `json:"scopes,omitempty"`
}

type OAuthAttachParams struct {
Provider string `json:"provider,omitempty"`
UserID string `json:"user_id,omitempty"`
SessionToken string `json:"session_token,omitempty"`
SessionJWT string `json:"session_jwt,omitempty"`
jeremy-stytch marked this conversation as resolved.
Show resolved Hide resolved
}

type OAuthAttachResponse struct {
RequestID string `json:"request_id,omitempty"`
StatusCode int `json:"status_code,omitempty"`
OAuthAttachToken string `json:"oauth_attach_token,omitempty"`
}
21 changes: 21 additions & 0 deletions stytch/oauth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,24 @@ func (c *Client) AuthenticateWithClaims(
retVal.Session.CustomClaims = wrapper.Session.Claims
return &retVal, err
}

func (c *Client) Attach(
body *stytch.OAuthAttachParams,
) (*stytch.OAuthAttachResponse, error) {
path := "/oauth/attach"

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 /oauth/attach request body")
}
}

var retVal stytch.OAuthAttachResponse
err = c.C.NewRequest("POST", path, nil, jsonBody, &retVal)
return &retVal, err
}