kytwb kytwb - 5 months ago 73
Android Question

OAuth and custom scheme result in a "ERR_UNKNOWN_URL_SCHEME" in Chrome

I've been stuck on this for hours now as the thing was working before but suddenly stopped to behave as expected. I don't really know how and why as I've been re-checking every single line of code in the process without being able to see what's wrong so I'm asking you guys for help.

Alright. So I've a

LoginScreen
activity with a button starting a new
Intent.ACTION_VIEW
on click. This start the OAUTH proccess in the browser with a
ApiManager.OAUTH_CALLBACK_URI
set to
stjapp://oauthresponse
.

Here's my
AndroidManifest.xml
part for this activity :

<activity
android:name=".LoginScreen"
android:label="@string/application"
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="stjapp" android:host="oauthresponse" />
</intent-filter>
</activity>


How I start the
Intent.ACTION_VIEW
in my activity :

private View.OnClickListener loginHandler = new View.OnClickListener() {
public void onClick(View v) {
OAuthClientRequest request = null;
try {
request = OAuthClientRequest
.authorizationLocation(ApiManager.OAUTH_AUTHORIZE)
.setClientId(ApiManager.CLIENT_ID).setRedirectURI(ApiManager.OAUTH_CALLBACK_URI)
.buildQueryMessage();
}
catch (OAuthSystemException e) { e.printStackTrace(); }
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(request.getLocationUri() + "&response_type=code"));
startActivity(intent);
}
};


And here's a screenshot of what happens in the browser :

enter image description here

There, I'm supposed to get back to my
LoginScreen
activity and handle the
code
query parameters within
onNewIntent
method but ... yeah, the thing doesn't work as expected anymore.

Any help appreciated.

Answer

It looks like this is a Chromium bug. The workaround I'm using is a PHP landing page for the RedirectURI that opens the app via JavaScript (which is not affected by that bug):

<script language="javascript">
    window.location = 'myscheme://myhost/?<?=$_SERVER["QUERY_STRING"]?>';
</script>
Comments