Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some help to get ionic-appauth to work on Android after upgrading from Capacitor V2 to Capacitor V3 #81

Open
wrzr123 opened this issue Dec 14, 2021 · 6 comments

Comments

@wrzr123
Copy link

wrzr123 commented Dec 14, 2021

Hey,

yesterday I was upgrading my Ionic app from Capacitor 2 to Capacitor 3, and I was struggeling a long time to get the redirect to work from my identity provider back to the app on a real Android device. I just want to document this for others who maybe also run into the same problem, so maybe it can just be transfered into some readme or stay here for others to be found.

  • Follow the normal upgrade steps described here
  • update ionic-appauth to latest (I'm using 0.8.5)
  • in your new Android app (if you were following the steps, you've deleted your Android application and it was recreated from scratch by running npx cap add android), open the AndroidManifest.xml of the main app
  • under the existing intent-filter, add another one (so you will have 2 intent-filters in the end):
<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" />
</intent-filter>

This is necessary to make the redirect back to the app work. It's not necessary to replace anything here with your own app-Id, it works like that.
It's strange, but with Capacitor 2 these lines were inserted automatically in the manifest. Now with Capacitor 3 you have to enter it manually.

@Ben555555
Copy link

Thanks for your contribution. I faced a similar issue, when using the demo for capacitor. On the mobile the device the InAppBrowser does not return to the app. I just get a blank screen. I tried to add your second intent-filter to the AndroidManifest.xml, but it still doesn't work. The file is located under angular-android\app\src\main\AndroidManifest.xml and looks like this:

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

    <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.appauth.demo.MainActivity"
            android:label="@string/title_activity_main"
            android:theme="@style/AppTheme.NoActionBarLaunch"
            android:launchMode="singleTask">

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

Do I have to add anything else here?

@Ben555555
Copy link

Ben555555 commented Jan 12, 2022

I was able to solve the issue by adding those 2 intents:

 <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="appauth" />
            </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:host=" " android:pathPrefix="/" android:scheme=" " />
            </intent-filter>

@wellwoller
Copy link

@Ben555555 @wrzr123 Would you be so kind and post the content of your string file?
I cant get this package to work and am really desperate. Also, did you make any changes since the update?

@wrzr123
Copy link
Author

wrzr123 commented May 24, 2023

What do you mean by string file?
Meanwhile we're at capacitor 4 and Android SDK 13, but at least in my AndroidManifest nothing has changed since my initial post.

I just noticed that the following bit:
<data android:scheme="@string/custom_url_scheme" />
is misleading. You have to replace "@string/custom_url_scheme" with you app ID, e.g. com.yourAppName.app. That was automatically replaced while I copied from my AndroidManifest to my GitHub-Post here.

@wellwoller
Copy link

@wrzr123 Sadly that doesnt solve my problem.
Could you tell me the content of your capacitor.config.ts?
Mine is:
appId: 'de.mydomain.myapp.app', appName: 'myappname', webDir: 'www', bundledWebRuntime: false, server: { iosScheme: "ionic", hostname: "de.mydomain.myapp.app" }

@wrzr123
Copy link
Author

wrzr123 commented May 24, 2023

I don't think it helps but here you go

{
  "appId": "com.myAppName.app",
  "appName": "myAppName",
  "bundledWebRuntime": false,
  "npmClient": "npm",
  "webDir": "www/de",
  "android": {
    "path": "android/app/src/main/assets/public"
  },
  "plugins": {
    "SplashScreen": {
      "launchShowDuration": 0
    }
  },
  "cordova": {}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants