It works perfectly on Android and iOS. In addition to Google Chrome on web and Microsoft Edge. This is with Firefox 107 (tested on Ubuntu and Windows 11). If I change back to our branch with SDK 45 it works in Firefox as well (only difference is upgraded packages).
We upgraded from SDK 45 to 47 so the change in the Expo AuthSession library that creates this behaviour in Firefox could possibly have been added in Expo 46.
We use this hook:
export function authenticate() {
const { signIn } = React.useContext(AuthContext);
const [request, authResponse, promptAuthentication] = AuthSession.useAuthRequest(
{
responseType: AuthSession.ResponseType.Code,
clientId: "clientId",
scopes: ["offline_access", "openid"],
redirectUri: AuthSession.makeRedirectUri({
native:"myvalidredirecturi",
}),
},
discovery,
);
React.useEffect(() => {
console.log("Authresponse: " + authResponse);
if (authResponse?.type === "success") {
AuthSession.exchangeCodeAsync(
{
clientId: "clientId",
redirectUri: AuthSession.makeRedirectUri({
native: "myvalidredirecturi",
}),
code: authResponse?.params.code,
extraParams: {
code_verifier: request.codeVerifier ? request.codeVerifier : "",
},
},
discovery,
).then((tResponse) => {
signIn(tResponse);
});
}
}, [authResponse]);
return promptAuthentication;
}
Used like this:
const features: WebBrowserWindowFeatures = {
popup: false,
};
const options: AuthRequestPromptOptions = {
windowFeatures: features,
};
const promptAuthentication = authenticate();
...
<TextButton
onPressButton={() =>
promptAuthentication(options).then((r) => {
if (Platform.OS == "web") {
navigation.navigate("Home");
}
})
}
text="Login"
/>
After debugging I have found out that it returns “success” inside the .then(r) after login, but the authResponse never gets set, so AuthSession.exchangeCodeAsync never runs. The browser console does not return any error, I just get redirected back to the login page (and in the address bar I can see state and session_state as query params for a brief second before it removes them upon refresh).
It has been hard to debug, any tips sure would be appreciated. I really hate these browser specific bugs.