in my expo app I get code and codeVerifier what a...
# ask-a-descoper
e
in my expo app I get code and codeVerifier what api should I call in backend to get the session token? I am trying with https://api.descope.com/v1/auth/oauth/exchange but it failed to exchange token
m
@Rahul Rijhwani can you help here
👀 1
e
yes
in my expo app const request = new AuthSession.AuthRequest({ clientId: DESCOPE_PROJECT_ID, responseType: AuthSession.ResponseType.Code, usePKCE: true, scopes: ["openid", "profile", "email", "descope.claims", "descope.custom_claims"], extraParams: { flow: flowId }, redirectUri, }); await request.makeAuthUrlAsync(discovery); const result = await request.promptAsync(discovery) if (result.type !== "success") { if (result.type === "dismiss") { return; } throw new Error(
Auth flow did not succeed: ${result.type}
); } const authCode = (result.params as any)?.code; await fetch(
${BackendAPI}/oauth/callback
, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ code: authCode, codeVerifier: request.codeVerifier }), }); in my backend await descopeClient.oauth.exchange(code, {codeVerifier});
r
Hi @EmilioDS Can you call this code in your backend with code which you are passing from expo app to your backend api. and also just put logs as well to check code is passing or not
const response = await descopeClient.oauth.exchange(code);
Refer doc: https://docs.descope.com/auth-methods/oauth/with-sdks/backend
e
error: { errorCode: 'E061301', errorDescription: 'Failed to exchange token', errorMessage: 'Failed exchanging sso token', message: 'Failed exchanging sso token' }
r
Can you share your project id @EmilioDS
e
P32agO594XhgOdt63ixQBJG3xbac
r
Hi @EmilioDS Let me debug this issue and will get back to you