Question about PKCE error when building app with expo

12 views
Skip to first unread message

张海洋

unread,
Oct 23, 2024, 5:02:24 PM10/23/24
to SMART on FHIR
Hi guys,
Just using expo to build an app which needs to connect with Epic, I'm using expo-auth-session as the auth library and here's the code:

import {
useAuthRequest,
CodeChallengeMethod,
makeRedirectUri,
} from "expo-auth-session"
const { codeChallenge, codeVerifier } = pkceChallenge();
const [ , , promptAsync] = useAuthRequest(
{
usePKCE: true,
responseType: "code",
clientId: epicClientId,
redirectUri,
scopes: ['fhirUser'],
codeChallengeMethod: CodeChallengeMethod.S256,
codeChallenge: codeChallenge,
extraParams: {
aud: 'my FHIR R4 URL'
}
},
{
authorizationEndpoint: 'authorizationEndpoint from epic',
tokenEndpoint: "tokenEndpoint from epic",
}
);

But always get the error like {"authentication": null, "error": [Error: The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. More info: PKCE required for unsecured redirects], "errorCode": null, "params": {"error": "invalid_request", "error_description": "PKCE required for unsecured redirects", "state": "6Tul1Tw6mW"}, "type": "error", "url": "exp://192.168.1.9:8081/?error=invalid_request&error_description=PKCE+required+for+unsecured+redirects&state=6Tul1Tw6mW"} I know expo is using url like exp://192.168.1.9:8081 locally, but I think I should set codeChallengeMethod and codeChallenge correctly, also set this as redirectURI in server's redirectURI list, so really dont know what's the problem, anyone has clues? Thanks a lot
Reply all
Reply to author
Forward
0 new messages