Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expo Google Login redirect to google.com in standalone

my app bild with Expo , i use import * as Google from "expo-google-app-auth"; for signin users from google. in development mode its work correcctly like expected. but in standalone mode ,

its redirect me to choose email, and after i choose its redirect me to google.com home page instead of back to my app

the question: why is redirect me to google and how can i handle that (again -- in development mode its work)

  1. my google sign in app

    try {
    const result = await Google.logInAsync({
        androidClientId: "556835760268-jm5v5u3h1bu4rcontent.com",
        androidStandaloneAppClientId: "556835760268-jm5v5u3h1bu4uea3jr788tent.com",
        scopes: ["profile", "email"],
    });
    
  2. my app.json file:

    {
    "expo": {
    "name": "Lior",
    "slug": "Lior",
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "scheme": "myapp",
    "splash": {
    "image": "./assets/splash.png",
    "resizeMode": "contain",
     "backgroundColor": "#ffffff"
      },
    
     "updates": {
     "fallbackToCacheTimeout": 0
     },
      "assetBundlePatterns": [
     "**/*"
     ],
      "ios": {
      "bundleIdentifier": "com.roei.liorApp",
       "buildNumber": "1.0.0"
         },
          "web": {
          "favicon": "./assets/favicon.png"
        },
      "android": {
       "package": "com.roei.liorApp",
       "versionCode": 1,
        "config": {
        "googleSignIn":{
       "apiKey": "AIzaSyD4K3trmw",
       "certificateHash": "89B503B4EDC94"
        },
        "googleMaps": {
         "apiKey": "AM35K3trmw"
     }
    

}

like image 947
Roei Grinshpan Avatar asked Dec 24 '20 13:12

Roei Grinshpan


1 Answers

I suspect the problem is just not specifying redirect URI information.

In general, your authenticator (Google in this case) needs to know where to send the user (i.e. what URL) after it's done authenticating. In my case, I use AuthSession and have to specify a redirectUri which is generated by AuthSession that will ultimately provide a return-path linked back into the app so it can automagically handle resuming App logic after login.

If the authenticator (Google) doesn't know where to send the user to after login, it doesn't seem unreasonable that it would just redirect you somewhere it considers safe (i.e. google's site).

As for the inconsistency with development mode, it's likely that some reasonable defaults are being made which aren't/can't/shouldn't in global mode for safety reasons. There's text on both AuthSession and Expo Google docs that speak to that type of inconsistency being expected. For example, here

Note on redirectUrl: If you choose to provide your own redirectUrl, it should start with the value returned by AppAuth.OAuthRedirect. This way, the method will function correctly and consistently whether you are testing in Expo Go or as a standalone app.

Also, if you haven't already, be sure to review and implement the specific instructions for Deploying to a standalone app on Android

Finally, consider switching to AuthSession because the previous answerer was correct in pointing out that it's marked as deprecated currently. You can see the giant deprecated banner at the top the doc pages as referred in this answer. If you have to get something working, might as well get it working with the latest supported version.

If you DO use AuthSession, check out this section containing the following references to how to generate a redirect URI

"AuthSession.makeRedirectUri() Create a redirect url for the current platform and environment. You need to manually define the redirect that will be used in a bare workflow React Native app, or an Expo standalone app, this is because it cannot be inferred automatically."

Note, when you set up the redirectUri feature, however you set it, you will need to also whitelist the URI on google side. That's because the authenticator (Google) needs to know that the URI pattern its being asked to hand over the credentials to is trustworthy. That way if someone tries to pretend to be you and get them to send your users' credentials to a non-trusted URL, Google won't do it.

like image 154
Atmas Avatar answered Oct 09 '22 11:10

Atmas