osmandapp / OsmAnd

OsmAnd
https://osmand.net
Other
4.56k stars 1k forks source link

Oauth2 login not working on old Android #20018

Open dfandrich opened 2 months ago

dfandrich commented 2 months ago

Description

The oauth2 login flow does not work on an old Android 7.1.2 phone running LineageOS 14.1. The web browser opens, OSM login credentials are entered, then the browser appears to redirect to a URL osmand-oauth://osmand.net/?code=XXX and displays the message:

Web page not available The web page at osmand-oauth://osmand.net/?code=XXX could not be loaded because:

net::ERR_UNKNOWN_URL_SCHEME

Needless to say, OSM authorization was not been set in OSMand. The web browser in use is not Chrome but rather the Lineage default Browser application org.lineageos.jelly ver. 7.1.2. There was no issue with the oauth1 flow on this OS (which I haven't done in a couple of years).

I tried manually running adb shell am start -a android.intent.action.VIEW -d 'osmand-oauth://osmand.net/?code=XXX' but it returned the message

Starting: Intent { act=android.intent.action.VIEW dat=osmand-oauth://osmand.net/?code=XXX }
Warning: Activity not started, its current task has been brought to the front

and while OSMand came to the foreground on the phone this time, it seemed to ignore the authorization code. I don't think this is related to the improper oauth2 scope issue mentioned in https://github.com/osmandapp/OsmAnd/pull/19966#issuecomment-2136407036 because it's clearly an issue with the integration between browser and application.

Steps to reproduce

Choose Login to OpenStreetMap and follow the Sign in with OpenStreetMap flow.

Actual result

net::ERR_UNKNOWN_URL_SCHEME

Expected result

OSM is seamlessly authorized in OSMand

Your Environment (required)

OsmAnd Version: 4.7.10
Android/iOS version: 7.1.2
Device model: Nexus 5/hammerhead
Crash-Logs: n/a
DmitryAlexei commented 2 months ago

@dfandrich

dfandrich commented 2 months ago

The browser version is 7.1.2 as in my original report. I don't have Google Play configured on this device so installing Chrome might not be straightforward. Here's a screenshot of the error screen (@maltfield, can you confirm this is what you're seeing, too?):

yuriiurshuliak commented 2 months ago

The bug could not be reproduced. I attempted to reproduce the issue by logging in through the "Sign in with OpenStreetMap" button. The web browser opened, I successfully logged into OpenStreetMap, and my account was displayed in the app.

Please ensure you are using the official version of the app and let us know if the error continues. Alternatively, you can try logging in using the "Use username and password" button.

OsmAnd~ 4.8.0#2460m, released: 2024-06-08 Version : 12

https://github.com/osmandapp/OsmAnd/assets/127092082/73e4096a-57c1-4899-86b5-4fd8e4ffd654

dfandrich commented 2 months ago

I'm using the OSM version on F-Droid. The "Use username & password" option works as a workaround, but a comment in #20017 leads me to believe that won't be working for long. What browser do you have as default? I suspect that's related.

dfandrich commented 2 months ago

I missed the request earlier to try https://osmand.net/map/ from my browser. That site, indeed, loads and works fine.

dfandrich commented 2 months ago

As an experiment, I installed the monocles browser from F-Droid, a small, System WebView-based (I believe) alternative browser. After setting it as the default browser, starting the OAuth2 authentication flow from OSMand once more, then enabling cookies in the browser before logging in, it succeeded. I could then uninstall monocles and continue using the OAuth2 credentials.

So, this seems a usable workaround for those suffering from this issue.

maltfield commented 2 months ago

If this bug exists with some browsers, then I think users should be able to copy and paste the keys directly between our own browser and the app.

OsmAnd should have some "manually enter keys" option, and documentation should describe how to use this if the browser <--> OsmAnd connection is broken.