Is it possible to obtain an access_token with expo-auth-session/providers/google?

Viewed 445

I am trying to obtain an access token for use with Google APIs using the up-to-date expo-auth-session package.

It works fine to fetch an id_token via useAuthRequest({responseType: "id_token", ...}) or useIdTokenAuthRequest({...})

However, when trying useAuthRequest({responseType: "code", ...}), I get the following error:

[Unhandled promise rejection: Error: The request is missing a required parameter, includes an unsupported parameter value (other than grant type), repeats a parameter, includes multiple credentials, utilizes more than one mechanism for authenticating the client, or is otherwise malformed.]

Does anyone know what is missing from the request? I am using the Expo Go app currently, so I'm not sure if that prevents obtaining an access token. Currently digging through the package's source code...

1 Answers

Add the following two props to useAuthRequest

shouldAutoExchangeCode: false,
clientSecret: 'any_bogus_value!'

shouldAutoExchangeCode will prevent the code from being exchanged and send it back to you in the response.

clientSecret will simply trigger and if check to be true in the providers source code that will avoid that error you specified being returned.

Note that in general it is not a good practice to avoid errors, but in this case, I feel like the error is being shown in error itself!

Related