From 69258805797873c3289a39e9e6d1c75d14bc3ff2 Mon Sep 17 00:00:00 2001 From: stevepodell Date: Wed, 25 Oct 2017 10:59:46 -0700 Subject: [PATCH] Added https://github.com/fullstackreact/react-native-oauth/pull/171 and my NSString *clientID fix, which might not be as good as https://github.com/fullstackreact/react-native-oauth/blob/2f8c8d1483526bbc8a6ca72183c6d11a71538ad3/ios/OAuthManager/OAuthManager.m --- .../fullstack/oauth/OAuthManagerModule.java | 21 ++++++++++++++++++- ios/OAuthManager/OAuthManager.m | 2 ++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/io/fullstack/oauth/OAuthManagerModule.java b/android/src/main/java/io/fullstack/oauth/OAuthManagerModule.java index 35777a4..b5f9a45 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; @@ -403,7 +404,25 @@ private WritableMap accessTokenResponse( 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); resp.putString("provider", providerName); diff --git a/ios/OAuthManager/OAuthManager.m b/ios/OAuthManager/OAuthManager.m index a9451bc..69ee707 100644 --- a/ios/OAuthManager/OAuthManager.m +++ b/ios/OAuthManager/OAuthManager.m @@ -304,6 +304,8 @@ - (NSDictionary *) getConfigForProvider:(NSString *)name DCTAuthAccount *existingAccount = [manager accountForProvider:providerName]; NSString *clientID = ((DCTOAuth2Credential *) existingAccount).clientID; + NSString *clientID = ([providerName isEqualToString:@"google"]) ? ((DCTOAuth2Credential *) existingAccount).clientID : (NSString *)nil; + if (([providerName isEqualToString:@"google"] && existingAccount && clientID != nil) || (![providerName isEqualToString:@"google"] && existingAccount != nil)) { if ([existingAccount isAuthorized]) {