[docs] AuthSession: Google - docs has errors for standalone apps
See original GitHub issueRelated: 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
orcom.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:
- Created 3 years ago
- Comments:10 (4 by maintainers)
Yeah. Swamped at the moment but I will PR all this + the related issue when that dies down 👍
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.