capacitor-community / generic-oauth2

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

Response not returned to calling javascript on Android #271

Open nisegami opened 3 weeks ago

nisegami commented 3 weeks ago

Description

Trying to use Google OAuth on Web+Android. Works fine in SPA. On Android, I see that the token is obtained successfully in the logs, but it is not returned to javascript successfully.

Capacitor version:

Output of npx cap doctor:

Latest Dependencies:       

  @capacitor/cli: 6.1.2    
  @capacitor/core: 6.1.2   
  @capacitor/android: 6.1.2

Installed Dependencies:    

  @capacitor/cli: 6.1.2    
  @capacitor/core: 6.1.2   
  @capacitor/android: 6.1.2

[success] Android looking great! 👌

Library version:

Using version 6.1.0 of the library.

OAuth Provider:

Your Plugin Configuration

{
        authorizationBaseUrl: 'https://accounts.google.com/o/oauth2/auth',
        accessTokenEndpoint: 'https://www.googleapis.com/oauth2/v4/token',
        scope: 'email profile',
        resourceUrl: 'https://www.googleapis.com/userinfo/v2/me',
        logsEnabled: false,
        web: {
            appId: config.public.googleWebClientId,
            accessTokenEndpoint: '',
            responseType: 'token',
            windowTarget: '_self',
            redirectUrl: `${config.public.appURL}/${action}/google`,
        },
        android: {
            appId: config.public.googleAndroidClientId,
            redirectUrl: `${config.public.androidPackageId}:/`,
            responseType: 'code',
            pkceEnabled: true,
        }
    }

Affected Platform(s):

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

    <!-- Permissions -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-feature android:name="android.hardware.location.gps" android:required="false" />

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
    <uses-feature android:name="android.hardware.camera" android:required="false" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="false"
        android:requestLegacyExternalStorage="true"
        android:theme="@style/AppTheme">
        <activity
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
            android:name=".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>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="@string/custom_url_scheme" android:host="app" />
            </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" />
        </provider>
    </application>
</manifest>
marcoelio commented 2 weeks ago

I have the same problem. I have searched and searched, I have tried many possible options, but I have not been able to solve the problem. Any solution please.