wi3land / ionic-appauth

Intergration for OpenId/AppAuth-JS into Ionic V3/4/5
MIT License
98 stars 73 forks source link

Auth.Instance.signIn() doesn't redirect to OAuth login page in Android #300

Open salesforcecodes opened 11 months ago

salesforcecodes commented 11 months ago

Implemented ionic-appauth package in an ionic react package. I am able to complete the sign in process in the web. But in Android it is not redirecting to the sign in screen.

Using latest ionic and capacitor version

"capacitor/cli": "5.5.1"
"ionic-appauth": "^2.0.0"
"@ionic/react": "^7.0.0"

Is this some issue with configuring AndroidManifest.xml? Here is my file

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

    <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">

        <activity
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
            android:name="com.mydomain.dev.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="com.mydomain.dev://callback" />
            </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>
salesforcecodes commented 11 months ago

I tried moving the android:scheme attribute as a string resource and removing ://callback at the end. Tried a bunch of other things as well. So far no luck. Appreciate any help! <data android:scheme="@string/custom_url_scheme" />

mraible commented 11 months ago

Have you added https://localhost as a Allowed Origins (CORS) on Auth0? This is required for Android.

salesforcecodes commented 11 months ago

@mraible Thank you for checking. I am using Salesforce as identity provider instead of Auth0. Does that matter. I have added localhost to act as redirect URL already.

mraible commented 11 months ago

I don't think the identity provider matters. Does Salesforce have an "allowed origins" or CORS setting you can configure?

salesforcecodes commented 11 months ago

Yeah. That is configured already and a simple oauth flow using the browser redirection works without issues. When I run it from the ionic app it is not launching the initial screen

YaMoef commented 10 months ago

@salesforcecodes hi, I had a similar issue. No CORS issues or errors but browser on android wouldn't open either. Turned out capacitor-secure-storage-plugin wasn't installed which is in the Vue demo. I suggest comparing all installed packages to one of the examples