Skip to content

Commit 6925880

Browse files
committed
1 parent 2a1fb1b commit 6925880

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

android/src/main/java/io/fullstack/oauth/OAuthManagerModule.java

+20-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.util.Log;
88

99
import com.google.gson.Gson;
10+
import com.google.gson.JsonSyntaxException;
1011

1112
import com.facebook.react.bridge.Arguments;
1213
import com.facebook.react.bridge.Callback;
@@ -403,7 +404,25 @@ private WritableMap accessTokenResponse(
403404
Map accessTokenMap = new Gson().fromJson(accessToken.getRawResponse(), Map.class);
404405

405406
Log.d(TAG, "Credential raw response: " + accessToken.getRawResponse());
406-
407+
408+
/* Some things return as JSON, some as x-www-form-urlencoded (querystring) */
409+
410+
Map accessTokenMap = null;
411+
try {
412+
accessTokenMap = new Gson().fromJson(accessToken.getRawResponse(), Map.class);
413+
} catch (JsonSyntaxException e) {
414+
/*
415+
failed to parse as JSON, so turn it into a HashMap which looks like the one we'd
416+
get back from the JSON parser, so the rest of the code continues unchanged.
417+
*/
418+
Log.d(TAG, "Credential looks like a querystring; parsing as such");
419+
accessTokenMap = new HashMap();
420+
accessTokenMap.put("user_id", accessToken.getParameter("user_id"));
421+
accessTokenMap.put("oauth_token_secret", accessToken.getParameter("oauth_token_secret"));
422+
accessTokenMap.put("token_type", accessToken.getParameter("token_type"));
423+
}
424+
425+
407426
resp.putString("status", "ok");
408427
resp.putBoolean("authorized", true);
409428
resp.putString("provider", providerName);

ios/OAuthManager/OAuthManager.m

+2
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ - (NSDictionary *) getConfigForProvider:(NSString *)name
304304

305305
DCTAuthAccount *existingAccount = [manager accountForProvider:providerName];
306306
NSString *clientID = ((DCTOAuth2Credential *) existingAccount).clientID;
307+
NSString *clientID = ([providerName isEqualToString:@"google"]) ? ((DCTOAuth2Credential *) existingAccount).clientID : (NSString *)nil;
308+
307309
if (([providerName isEqualToString:@"google"] && existingAccount && clientID != nil)
308310
|| (![providerName isEqualToString:@"google"] && existingAccount != nil)) {
309311
if ([existingAccount isAuthorized]) {

0 commit comments

Comments
 (0)