OAuth的和定制方案导致A" ERR_UNKNOWN_URL_SCHEME"在Chrome浏览器浏览器、方案、OAuth、QUOT

2023-09-04 07:20:03 作者:软了一个趴

我已经被困在这几个小时,现在的事情是工作之前,但突然停下来像预期的那样。我真的不知道如何和为什么,因为我一直在重新检查code的过程中每一行,而不能看到什么是错的,所以我请求你们的帮助。

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.

好吧。所以我有一个 LoginScreen 活动的一个按钮启动一个新的 Intent.ACTION_VIEW 上点击。这开始OAuth的proccess在浏览器中的 ApiManager.OAUTH_CALLBACK_URI 设置为 stjapp:// oauthresponse

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.

下面是我的的Andr​​oidManifest.xml 部分为这项活动:

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>

我如何启动 Intent.ACTION_VIEW 在我的活动:

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 :

在那里,我应该回到我的 LoginScreen 活动并办理 code 查询在 onNewIntent参数方法,但...是啊,事情并不如预期的工作了。

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.

任何帮助AP preciated。

Any help appreciated.

推荐答案

看起来这是一个的铬错误。我使用的解决方法是一个PHP登陆页面RedirectURI打开通过JavaScript应用程序(它是不会受到错误):

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>