From f727a7c7676aa0af6e5fdc26ec0122e0c4041781 Mon Sep 17 00:00:00 2001 From: Rustem Mussabekov Date: Tue, 12 Sep 2017 18:04:33 +0300 Subject: [PATCH 1/3] Update OAuthManager.h --- ios/OAuthManager/OAuthManager.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ios/OAuthManager/OAuthManager.h b/ios/OAuthManager/OAuthManager.h index 4f653e4..7a2d783 100644 --- a/ios/OAuthManager/OAuthManager.h +++ b/ios/OAuthManager/OAuthManager.h @@ -7,10 +7,10 @@ #import -#if __has_include("RCTBridgeModule.h") - #import "RCTBridgeModule.h" +#if __has_include() + #import #else - #import + #import "RCTBridgeModule.h" #endif #if __has_include("RCTLinkingManager.h") From 470ffaa60774ea9418ed8772680dc0dfa97630ee Mon Sep 17 00:00:00 2001 From: Rustem Mussabekov Date: Wed, 27 Sep 2017 17:15:34 +0100 Subject: [PATCH 2/3] Update build.gradle --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index b9ff010..18ac8b7 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -14,7 +14,7 @@ apply plugin: 'maven' android { compileSdkVersion 23 - buildToolsVersion "23.0.1" + buildToolsVersion "25.0.1" defaultConfig { minSdkVersion 16 From c0af6d8f76a99fd8d1cec5ce4745526f64d3ffc8 Mon Sep 17 00:00:00 2001 From: Stuart Langridge Date: Mon, 16 Oct 2017 15:51:02 +0100 Subject: [PATCH 3/3] Twitter, for example, returns OAuth token data as a querystring (x-www-form-urlencoded), not as JSON, so signing in breaks as per https://github.com/fullstackreact/react-native-oauth/issues/165. Correct this by catching the JSON parse error and falling back to extracting the parameters we need from the token instead. --- .../fullstack/oauth/OAuthManagerModule.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/io/fullstack/oauth/OAuthManagerModule.java b/android/src/main/java/io/fullstack/oauth/OAuthManagerModule.java index 35777a4..a8ee1a3 100644 --- a/android/src/main/java/io/fullstack/oauth/OAuthManagerModule.java +++ b/android/src/main/java/io/fullstack/oauth/OAuthManagerModule.java @@ -7,6 +7,7 @@ import android.util.Log; import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.Callback; @@ -400,9 +401,25 @@ private WritableMap accessTokenResponse( ) { WritableMap resp = Arguments.createMap(); WritableMap response = Arguments.createMap(); - Map accessTokenMap = new Gson().fromJson(accessToken.getRawResponse(), Map.class); - Log.d(TAG, "Credential raw response: " + accessToken.getRawResponse()); + + /* Some things return as JSON, some as x-www-form-urlencoded (querystring) */ + + Map accessTokenMap = null; + try { + accessTokenMap = new Gson().fromJson(accessToken.getRawResponse(), Map.class); + } catch (JsonSyntaxException e) { + /* + failed to parse as JSON, so turn it into a HashMap which looks like the one we'd + get back from the JSON parser, so the rest of the code continues unchanged. + */ + Log.d(TAG, "Credential looks like a querystring; parsing as such"); + accessTokenMap = new HashMap(); + accessTokenMap.put("user_id", accessToken.getParameter("user_id")); + accessTokenMap.put("oauth_token_secret", accessToken.getParameter("oauth_token_secret")); + accessTokenMap.put("token_type", accessToken.getParameter("token_type")); + } + resp.putString("status", "ok"); resp.putBoolean("authorized", true);