MaikuB / flutter_appauth

A Flutter wrapper for AppAuth iOS and Android SDKs
274 stars 246 forks source link

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

Open mohsinnaqvi606 opened 1 month ago

mohsinnaqvi606 commented 1 month ago

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',
        ),
      ),
    );
nbnD commented 1 month ago

did you solved this?

mohsinnaqvi606 commented 1 month ago

Not yet. still trying to figure out

FAArik commented 1 month ago

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

mohsinnaqvi606 commented 1 month ago

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

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

FAArik commented 1 month ago

@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)

mohsinnaqvi606 commented 1 month ago

@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

FAArik commented 1 month ago

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

MaikuB commented 1 month ago

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