flutter_appauth icon indicating copy to clipboard operation
flutter_appauth copied to clipboard

[Android] Browser is not redirecting the user back to the app

Open mohsinnaqvi606 opened this issue 1 year ago • 10 comments

I am implementing Google OAuth 2.0 for Flutter Android, but the browser is not redirecting the user back to the app. Do I need deep linking for this, or can I manage it through a custom URI?

I have created Client ID for Web application and added same redirect URL https://companyname.com/api/oauth/google/callback I also added domain companyname.com on OAuth consent screen under Authorized domains

Here is my code

build.gradle

 defaultConfig {

        manifestPlaceholders += [
                appAuthRedirectScheme: 'https'
        ]
        //other config
 }

AndroidManifest.xml

  <activity android:name="net.openid.appauth.RedirectUriReceiverActivity">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="https" android:host="companyname.com" />
            </intent-filter>
        </activity>

Flutter Code

    final FlutterAppAuth appAuth = FlutterAppAuth();

    final AuthorizationTokenResponse? result =
        await appAuth.authorizeAndExchangeCode(
      AuthorizationTokenRequest(
        'xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com',
        'https://companyname.com/api/oauth/google/callback',
        scopes: ['openid', 'profile', 'email'],
        serviceConfiguration: AuthorizationServiceConfiguration(
          authorizationEndpoint: 'https://accounts.google.com/o/oauth2/v2/auth',
          tokenEndpoint: 'https://oauth2.googleapis.com/token',
        ),
      ),
    );

mohsinnaqvi606 avatar Oct 01 '24 05:10 mohsinnaqvi606

did you solved this?

nbnD avatar Oct 02 '24 08:10 nbnD

Not yet. still trying to figure out

mohsinnaqvi606 avatar Oct 02 '24 08:10 mohsinnaqvi606

I am encountering the same issue with Keycloak OIDC. I can see my session in Keycloak, but the application gets stuck in the browser.

FAArik avatar Oct 02 '24 12:10 FAArik

@FAArik , @nbnD I think nobody is available for a reply

Please vote this question for quick reply https://stackoverflow.com/q/79049260/16043732

mohsinnaqvi606 avatar Oct 03 '24 06:10 mohsinnaqvi606

@mohsinnaqvi606 i don't know if that that could fix your problem When i put

          <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="https" android:host="companyname.com" />
            </intent-filter>

image

inside .MainActivity i get redirected to my app but i cant get token and recieve this error

Login failed: PlatformException(null_intent, Failed to authorize: Null intent received, null, null)

FAArik avatar Oct 03 '24 06:10 FAArik

@FAArik I am even unable to open the App from the browser. Are you using deep-linking?

Please share your code [Flutter side & native configuration] and the steps you followed on the Google console

mohsinnaqvi606 avatar Oct 03 '24 07:10 mohsinnaqvi606

@mohsinnaqvi606 https://gist.github.com/FAArik/0c4af32ce8fbe398e7c97ae737ba83f5

FAArik avatar Oct 03 '24 08:10 FAArik

If you have redirect issues then it's a configuration issue that you would need to look into. One thing that sticks out is you're indicating that you've specified a website. Each platform has their own requirements that need to be followed to deal with this that you need to look into to ensure this is configured properly. To clarify, these aren't requirements required by the plugin or the AppAuth SDKs themselves so is outside the scope of the plugin. You would need to look up the official Android and iOS/macOS/Apple docs for these

MaikuB avatar Oct 04 '24 11:10 MaikuB

I removed this line android:taskAffinity="" and intent filter - this removed the issue of "open with" in the manifest xml and it worked.

wisemiro avatar Mar 29 '25 06:03 wisemiro

I removed this line android:taskAffinity="" and intent filter - this removed the issue of "open with" in the manifest xml and it worked.

My friend If I ever meet you owe you a beer.

VVucenic avatar Aug 29 '25 12:08 VVucenic