Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working on Android 8.0 Oreo #165

Open
ujeenator opened this issue Sep 25, 2017 · 2 comments
Open

Not working on Android 8.0 Oreo #165

ujeenator opened this issue Sep 25, 2017 · 2 comments

Comments

@ujeenator
Copy link

ujeenator commented Sep 25, 2017

Facebook login fails with "Sorry something went wrong" message

Google login just hangs after entering the password

@ujeenator ujeenator changed the title Not working on Android Oreo Not working on Android 8.0 Oreo Sep 25, 2017
@SailingSteve
Copy link
Contributor

SailingSteve commented Oct 2, 2017

With 8.0, for me in OAuthManagerModule.java

private WritableMap accessTokenResponse()

receives a OAuth2AccessToken that looks more like a payload from a URL separated by ampersands (not Json) and the GSON parser crashes on receiving it in about line 404. Even if it were properly formatted Json, it would not contain the "user_id" that we need.

Map accessTokenMap = new Gson().fromJson(accessToken.getRawResponse(), Map.class);

I backed down to 7.1 and avoided this crash.

@stuartlangridge
Copy link

stuartlangridge commented Oct 16, 2017

I'm seeing possibly the same issue on Android 6.0. Logcat:

10-16 10:30:37.079  3051  3051 D OauthFragment: onPageFinished: https://api.twitter.com/oauth/authorize
10-16 10:30:37.079  3051  3051 I OauthFragment: interceptUrl called with url: http://localhost/twitter?oauth_token=BBBBBBBB&oauth_verifier=CCCCCCCC
10-16 10:30:37.080  3051  3112 I System.out: obtaining access token from https://api.twitter.com/oauth/access_token
10-16 10:30:37.080  3051  3112 I System.out: setting token to: OAuth1RequestToken{oauth_token=BBBBBBBB, oauth_token_secret=mY5y4Ks22GANEYlPeoY14EY2tG9FYs0u, oauth_callback_confirmed=true} and verifier to: CCCCCCCC
10-16 10:30:37.080  3051  3112 I System.out: generating signature...
10-16 10:30:37.080  3051  3112 I System.out: using base64 encoder: CommonsCodec
10-16 10:30:37.227  3051  3112 I System.out: base string is: POST&https%3A%2F%2Fapi.twitter.com%2Foauth%2Faccess_token&oauth_consumer_key%3DDDDDDDDDDDD%26oauth_nonce%3DEEEEEEEEEEEEEE%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1508146237%26oauth_token%3DBBBBBBBB%26oauth_verifier%3DCCCCCCCC%26oauth_version%3D1.0
10-16 10:30:37.227  3051  3112 I System.out: signature is: SSSSSSSSSSSSSS
10-16 10:30:37.227  3051  3112 I System.out: appended additional OAuth parameters: { oauth_signature_method -> HMAC-SHA1 , oauth_consumer_key -> DDDDDDDDDDD , oauth_version -> 1.0 , oauth_timestamp -> 1508146237 , oauth_nonce -> EEEEEEEEEEEEEE , oauth_verifier -> CCCCCCCC , oauth_token -> BBBBBBBB , oauth_signature -> SSSSSSSSSSSSSS }
10-16 10:30:37.227  3051  3112 I System.out: using Http Header signature
10-16 10:30:37.550  3051  3163 D TSLocationManager: [c.t.l.BackgroundGeolocationService onActivityRecognitionResult] still (100%)
10-16 10:30:37.727  3051  3051 D OAuthManager: Loaded access token in OAuthManagerFragmentController
10-16 10:30:37.727  3051  3051 D OAuthManager: AccessToken: OAuth1AccessToken{oauth_token=9999-TTTTT, oauth_token_secret=FFFFFFFFFF} (raw: oauth_token=9999-TTTTT&oauth_token_secret=FFFFFFFFFF&user_id=8888888&screen_name=NNNNNNN&x_auth_expires=0)
10-16 10:30:37.891  3051  3051 D OAuthManagerStore: Preferences changed: twitter
10-16 10:30:37.892  3051  3051 D AndroidRuntime: Shutting down VM
--------- beginning of crash
10-16 10:30:37.892  3051  3051 E AndroidRuntime: FATAL EXCEPTION: main
10-16 10:30:37.892  3051  3051 E AndroidRuntime: Process: (snip), PID: 3051
10-16 10:30:37.892  3051  3051 E AndroidRuntime: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
10-16 10:30:37.892  3051  3051 E AndroidRuntime:    at com.google.gson.Gson.fromJson(Gson.java:900)
10-16 10:30:37.892  3051  3051 E AndroidRuntime:    at com.google.gson.Gson.fromJson(Gson.java:853)
10-16 10:30:37.892  3051  3051 E AndroidRuntime:    at com.google.gson.Gson.fromJson(Gson.java:802)
10-16 10:30:37.892  3051  3051 E AndroidRuntime:    at com.google.gson.Gson.fromJson(Gson.java:774)
10-16 10:30:37.892  3051  3051 E AndroidRuntime:    at io.fullstack.oauth.OAuthManagerModule.accessTokenResponse(OAuthManagerModule.java:403)
10-16 10:30:37.892  3051  3051 E AndroidRuntime:    at io.fullstack.oauth.OAuthManagerModule.access$100(OAuthManagerModule.java:45)
10-16 10:30:37.892  3051  3051 E AndroidRuntime:    at io.fullstack.oauth.OAuthManagerModule$1.onOAuth1AccessToken(OAuthManagerModule.java:128)
10-16 10:30:37.892  3051  3051 E AndroidRuntime:    at io.fullstack.oauth.OAuthManagerFragmentController.loaded10aAccessToken(OAuthManagerFragmentController.java:147)

I don't think it's Android-version specific. The code in question is:

    Map accessTokenMap = new Gson().fromJson(accessToken.getRawResponse(), Map.class);

and accessToken.getRawResponse() looks like this (from a Twitter transaction, and with newlines added for ease of reading):

auth_token=9999999999-AAAAAAAAAAAAAAAAAAAAAAA&
oauth_token_secret=AAAAAAAAAAAAAAAAAAAAAA
&user_id=9999999999
&screen_name=mytwittername
&x_auth_expires=0

so the issue is as @SailingSteve reports that the code is expecting JSON back and it's getting a querystring (x-www-form-urlencoded) instead. What I don't understand is how this ever worked -- https://developer.twitter.com/en/docs/basics/authentication/api-reference/access_token is clear that oauth tokens are returned as a querystring. So I must be missing something.

(I think that 2a1c0fb#diff-9fc211ef231ecaa3ee7613d9696db4a1 is the commit which changed code to parse the response as JSON, instead of as a querystring.)

stuartlangridge added a commit to stuartlangridge/react-native-oauth that referenced this issue Oct 16, 2017
(x-www-form-urlencoded), not as JSON, so signing in breaks as per
fullstackreact#165.
Correct this by catching the JSON parse error and falling back to
extracting the parameters we need from the token instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants