@privy-io/js-sdk-core
Version:
Vanilla JS client for the Privy Auth API
2 lines (1 loc) • 1.28 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@privy-io/public-api"),t=require("../../Error.js"),r=require("../../pkce.js");require("jose");exports.default=class{async generateURL(t){let i=r.createCodeVerifier(),a=r.createStateCode(),o=await r.deriveCodeChallengeFromCodeVerifier({codeVerifier:i,digest:this._crypto?.digest});return await Promise.all([this._storage.put(r.CODE_VERIFIER_KEY,i),this._storage.put(r.STATE_CODE_KEY,a)]),this._privyInternal.fetch(e.RecoveryOAuthInit,{body:{redirect_to:t,code_challenge:o,state_code:a}})}async authorize(i,a){let[o,s]=await Promise.all([this._storage.get(r.CODE_VERIFIER_KEY),this._storage.get(r.STATE_CODE_KEY)]);if(s!==a)throw this._privyInternal.createAnalyticsEvent("possible_phishing_attempt",{flow:"recovery_oauth",storedStateCode:s??"",returnedStateCode:a??""}),new t.PrivyClientError({code:"pkce_state_code_mismatch",error:"Unexpected auth flow. This may be a phishing attempt."});let _=await this._privyInternal.fetch(e.RecoveryOAuthAuthenticate,{body:{authorization_code:i,state_code:s,code_verifier:o}});return await Promise.all([this._storage.del(r.CODE_VERIFIER_KEY),this._storage.del(r.STATE_CODE_KEY)]),_}constructor(e,t,r){this._privyInternal=e,this._storage=t,this._crypto=r}};
;