Skip to content

Commit

Permalink
feat: add SSO PKCE (#707)
Browse files Browse the repository at this point in the history
## What kind of change does this PR introduce?

Companion PR to: supabase/auth#1137

Server-Side PR: PKCE supabase/auth#1137

Co-authored-by: joel@joellee.org <joel@joellee.org>
  • Loading branch information
J0 and joel@joellee.org committed Oct 20, 2023
1 parent 58a1ee6 commit ba66b4d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,14 @@ export default class GoTrueClient {
async signInWithSSO(params: SignInWithSSO): Promise<SSOResponse> {
try {
await this._removeSession()
let codeChallenge: string | null = null
let codeChallengeMethod: string | null = null
if (this.flowType === 'pkce') {
const codeVerifier = generatePKCEVerifier()
await setItemAsync(this.storage, `${this.storageKey}-code-verifier`, codeVerifier)
codeChallenge = await generatePKCEChallenge(codeVerifier)
codeChallengeMethod = codeVerifier === codeChallenge ? 'plain' : 's256'
}

return await _request(this.fetch, 'POST', `${this.url}/sso`, {
body: {
Expand All @@ -719,6 +727,8 @@ export default class GoTrueClient {
? { gotrue_meta_security: { captcha_token: params.options.captchaToken } }
: null),
skip_http_redirect: true, // fetch does not handle redirects
code_challenge: codeChallenge,
code_challenge_method: codeChallengeMethod,
},
headers: this.headers,
xform: _ssoResponse,
Expand Down

0 comments on commit ba66b4d

Please sign in to comment.