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 :
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.
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):
only if you are manually entering the URL of the redirect page in the address bar. The issue is on the chromium issue tracker here.
The response with the "workaround", pasted from the issue:
OK, I've found out that the window.location redirect via intent will work, AS LONG as it is clicked from an external source or link on page. If you manually enter the address of the redirect page into the address bar, the redirection / opening of the app will fail with said error.
So, sending a link to the redirect page in an email or SMS will work just fine when the user clicks the link. Manually typing the address into the address bar will fail. window.location = chromeUrl; should work just fine.
In Chrome version 40 and up, this bug has resurfaced, but only if you are manually entering the URL of the redirect page in the address bar. The issue is on the chromium issue tracker here.
The response with the "workaround", pasted from the issue:
I had the same error and resolved it by prefixing the url with
http://
.