question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[docs] AuthSession: Google - docs has errors for standalone apps

See original GitHub issue

Related: https://github.com/expo/expo/issues/9391.

My guess is that either I have missed a vital step, or that the following was only ever tested in isolation, and not e2e.

Documentation assumes using proxy always

The documentation says to add the following code:

const useProxy = Platform.select({
  web: false,
  default: true
});

The above will make the standalone app use the proxy. The proxy won’t send the request back to your app (see below why). But we probably want the following anyway:

const useProxy = Platform.select({
  web: false,
  default: Constants.appOwnership === 'expo',
});

Incorrect native redirect URI

The documentation lists the following:

com.googleusercontent.apps.GUID://redirect

Using this redirect uri will result in a 400: invalid_request with the error that the redirect_uri parameter is incorrect and “cannot have authority”. First feeling is to check the credentials page. Here the correct/same scheme is listed in the key if you follow the link on the credentials page (only for iOS keys).

Removing the authority part will result in:

com.googleusercontent.apps.GUID:

# or com.googleusercontent.apps.GUID://
  • Leaving out the colon (:) results into the error “Missing scheme”
  • Using the above doesn’t work, because the Auth session will never get the redirection, and thus it breaks (it will redirect to google.com).

From the google documentation:

redirect_uri_path is an optional path component, such as /oauth2redirect. Note that the path should begin with a single slash, which is different from regular HTTP URLs.

But even when using the following (which doesn’t error), the app doesn’t redirect to “the app”, but to google.com instead:

com.googleusercontent.apps.GUID:/redirect

Why?

Because com.googleusercontent.apps.GUID is not our scheme, so the app will not respond to this redirection. Okay so just set the scheme to com.googleusercontent.apps.GUID? No, because you will have a different GUID for Android and iOS.

Solution(s)

redirectUri: makeRedirectUri({
  // For usage in bare and standalone
  native: Platform.select({ 
    android: `com.googleusercontent.apps.${GOOGLE_GUID_FOR_ANDROID}:`,
    ios: `com.googleusercontent.apps.${GOOGLE_GUID_FOR_IOS}:`,
  }),
  useProxy,
})
  • In order to set this up correctly for Android, “app links” for a custom scheme have to be added.
  • In order to set this up correctly for iOS, the scheme needs to be added to the Info.plist

Package Name and Bundle Identifier match scheme

There is a third option:

Again using the google documentation:

The table below shows the appropriate redirect_uri parameter value for each method:

com.example.app:redirect_uri_path or com.googleusercontent.apps.123:redirect_uri_path

com.example.app is the reverse DNS notation of a domain under your control. The custom scheme must contain a period to be valid.

Fun fact. According to some documentation from 2013, which is on Google Plus and thus no longer readible, you can also use the bundle identifier or package name for the scheme. These are set-up automatically for a client key. This is not documented on the credentials portal.

In this case it’s straigh-forward:

native: `${Constants.manifest.scheme}:`,

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
SleeplessBytecommented, Jul 30, 2020

Yeah. Swamped at the moment but I will PR all this + the related issue when that dies down 👍

0reactions
github-actions[bot]commented, Aug 16, 2022

This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AuthSession returns dismiss result on Android standalone app
The result is that, when an app is running on Android as a standalone app, every authentication attempt returns dismiss.
Read more >
Google provider does not work in standalone build - Expo SDK
Has anyone got the “new” google provider in expo-auth-session to work in a standalone apk? I just get a result type of “dismiss”....
Read more >
Expo - ReactNative - AuthSession with Google does not work ...
In expo it works, Google returns all I need, but in Standalone, Google throws an error that such response type is unsupported. If...
Read more >
Expo Auth Session for Google Authentication on React Native ...
Hi everyone!SKIP INTRO and go straight to code: 2:28Today I am going to talk about Expo AuthSession with the Google provider and some ......
Read more >
Using OAuth 2.0 to Access Google APIs | Authorization
Then your client application requests an access token from the Google Authorization Server, extracts a token from the response, and sends the token...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found