Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
448 views
in Technique[技术] by (71.8m points)

android - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...