expo-auth-session problem with redirecting back to app (Android only) iOS works perfect

262 Views Asked by At

Detailed description of problem:
After login (in my way it is Microsoft - Azure), Expo gives me this error:

https://ctrlv.link/ruqB

Log saying:

https://ctrlv.link/Rpb0

In my opinion, there's a problem with redirecting back from Google Chrome login, Safari (iOS) opens directly into the expo app, while Android has to open an external source of the browser.

There is some source of code:

// Endpoint
const discovery = useAutoDiscovery(`https://login.microsoftonline.com/${tenantID}/v2.0`);

// Request
const [request, response, promptAsync] = useAuthRequest(
  {
    clientId: process.env.EXPO_PUBLIC_CLIENT_ID,
    scopes: ["openid", "profile", "email", "offline_access", "User.Read.All"],
    redirectUri: process.env.EXPO_PUBLIC_REDIRECT_URI,
  },
  discovery
);

Am using a method from expo documentation:
https://docs.expo.dev/guides/authentication/#azure

Login source

const handleLogin = async () => {
  try {
    const codeResponse = await promptAsync();

    if (request && codeResponse?.type === "success" && discovery) {
      const res = await exchangeCodeAsync(
        {
          clientId,
          code: codeResponse.params.code,
          extraParams: request.codeVerifier
            ? { code_verifier: request.codeVerifier }
            : undefined,
          redirectUri,
        },
        discovery
      );

      setToken(res.accessToken);
      await gettingAllDatas(); // Fetch and store data here
    }
  } catch (error) {
    console.error("Error handling login:", error);
  }
};

Thanks for your responses :)

0

There are 0 best solutions below