capacitor-community / generic-oauth2

Generic Capacitor OAuth 2 client plugin. Stop the war in Ukraine!
MIT License
223 stars 106 forks source link

Bug: Intent filter not working for redirection after login #231

Open MGX-CODING opened 1 year ago

MGX-CODING commented 1 year ago

Capacitor version:

Run npx cap doctor:

πŸ’Š   Capacitor Doctor  πŸ’Š 

Latest Dependencies:

  @capacitor/cli: 4.7.0
  @capacitor/core: 4.7.0
  @capacitor/android: 4.7.0
  @capacitor/ios: 4.7.0

Installed Dependencies:

  @capacitor/cli: 4.6.3
  @capacitor/core: 4.6.3
  @capacitor/android: 4.6.3
  @capacitor/ios: 4.6.3

[success] Android looking great! πŸ‘Œ

Library version:

    "@byteowls/capacitor-oauth2": "^4.0.0",

OAuth Provider:

I would say none ?
I would assume my company uses some custom implementation, but something I can tell you for sure is that Oauth2/OIDC work perfectly on the web with the library angular-oauth2-oidc, if that can help

Your Plugin Configuration

    OAuth2Client.authenticate({
      authorizationBaseUrl: 'https://mycompanyurl/openam/oauth2/preprod/authorize',
      redirectUrl: location.origin,
      responseType: 'code',
      pkceEnabled: true,
      appId: 'myappclientid,
      scope: 'my scope',
    }).then(res => {
      console.log('RESPONSE');
      console.log(res);
    });

Affected Platform(s):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="myPackageName">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:networkSecurityConfig="@xml/network_security_config">

        <activity
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
            android:name="myPackageName.MainActivity"
            android:label="@string/title_activity_main"
            android:theme="@style/AppTheme.NoActionBarLaunch"
            android:launchMode="singleTask"
            android:exported="true">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter>
              <data android:scheme="@string/custom_url_scheme" android:host="localhost" />
              <action android:name="android.intent.action.VIEW"/>
              <category android:name="android.intent.category.DEFAULT"/>
              <category android:name="android.intent.category.BROWSABLE"/>
            </intent-filter>

        </activity>

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths"></meta-data>
        </provider>
    </application>

    <!-- Permissions -->

    <uses-permission android:name="android.permission.INTERNET" />
</manifest>

Current Behavior

The redirection to the login form works great, I can input my credentials, but then, the redirect back to my application does not work.

I followed the Android guidelines for the library and I cannot pinpoint the issue I am facing.

I tried modifying the intent filter and the capacitor config a lot of times and nothing seems to work.

Please keep in mind, I'm a JS developer, my knowledge of Java / Android is limited !

Expected Behavior

Should work

Sample Code or Sample Application Repo

Sorry, no reproduction possible ...

Other Information

Capacitor config file : I have to edit the server scheme and host for CORS, and also for Oauth redirect URLs. Would that be the issue ?

import { CapacitorConfig } from '@capacitor/cli';

export default {
  bundledWebRuntime: false,
  server: {
    cleartext: true,
    androidScheme: 'http',
    hostname: 'localhost:4200',
  },
  plugins: {
    LocalNotifications: {
      smallIcon: 'ic_stat_icon_config_sample',
      iconColor: '#488AFF',
      sound: 'beep.wav',
    },
  },
  appId: 'MyAppId',
  appName: 'MyAppName',
  webDir: 'dist/pwa_MyAppName',
  android: {
    allowMixedContent: true,
    flavor: 'dev',
  },
  ios: {
    scheme: `MyAppName - dev`,
  },
} as CapacitorConfig;
JacquesBeets commented 1 year ago

Getting a similar issue on our side as well.

di-appteam commented 1 year ago

Any update, I am facing same issue