Gets ERR_NAME_NOT_RESOLVED on oauth callback

My Ionic Info
@capacitor/cli”: “^3.4.3”,

I’m implementing oauth2 on an Ionic React app for Android but when receive the callback with the code and status, the webview shows an ERR_NAME_NOT_RESOLVED.

In the capacitor config.json I forze https for the app:

"server": {
    "iosScheme": "ionic",
    "androidScheme": "https",
    "hostname": "com.gronze.maps",
....

In the android manifest I use an intent filter

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

and in the strings.xml I use the custom_url_scheme
<string name="custom_url_scheme">com.gronze.maps</string>

When calls to the mydomain/oauth2/authorize with the oauth params, my server sends the callback
https://com.gronze.maps/?code=&state=m8882
but the app shows a blanck page with the ERR_NAME_NOT_RESOLVED.

Captura de Pantalla 2022-08-23 a las 16.28.57

But if I reload the webview with this url, the app works fine again.
What is happening? it fails on callback but works if reload

If instead of com.gronze.maps I use localhost, and the callback received is https://localhost/?code=&state=m8882 the page shows an ERR_CON_REFUSED and if I try to reload it works again

Captura de Pantalla 2022-08-23 a las 16.25.27

Thanks!
Jorge

You are using the URL Scheme wrong. You’re specifying com.gronze.maps as your custom URL scheme, but then trying to load it with https as the scheme. It more likely should be com.gronze.maps://url?code=blah.

Long term though, you’d be better off using App/Universal links for this. Custom URL Schemes are quick and effective, but anyone can add whatever they want to their app, so if someone wanted to create an app to hijack calls into your application, they just register their application with the same scheme. We have documentation around using the better links here in the Capacitor Docs. Though to be clear, if you’re just testing, or this is a personal project, you’re probably okay using custom URL schemes.

Hope this helps!

thanks Dallas!

I tried to change my config:

  "server": {
    "iosScheme": "gronze",
    "androidScheme": "gronze",
    "hostname": "com.gronze.maps",
    "allowNavigation": [
      "gronze.com",
      "*.gronze.com",
      "*.gronze.*"
    ]
  }

The app sends the request with the redirect url gronze://com.gronze.maps:
https://test.gronze.com/oauth2/authorize?response_type=code&client_id=mi_id&redirect_uri=gronze%3A%2F%2Fcom.gronze.maps&scope=maps_gronze&state=wg555

but the app shows a white page and the url is fixed on the request url
https://test.gronze.com/oauth2/authorize?response_type=code&client_id=mi_id&redirect_uri=gronze%3A%2F%2Fcom.gronze.maps&scope=maps_gronze&state=wg555

and in the network tab that request is shown as a 200 ok response

what am I doing wrong?

thanks!
Jorge