Skip to content

Commit 87786d6

Browse files
authored
Merge pull request #182 from SailingSteve/master
Fixes for Java/GSON syntax exception and issue #142
2 parents e7ac4a8 + 370c065 commit 87786d6

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

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

+20-2
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;
@@ -400,10 +401,27 @@ private WritableMap accessTokenResponse(
400401
) {
401402
WritableMap resp = Arguments.createMap();
402403
WritableMap response = Arguments.createMap();
403-
Map accessTokenMap = new Gson().fromJson(accessToken.getRawResponse(), Map.class);
404404

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

ios/OAuthManager/OAuthManager.m

+2-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ - (NSDictionary *) getConfigForProvider:(NSString *)name
307307
NSMutableDictionary *cfg = [[manager getConfigForProvider:providerName] mutableCopy];
308308

309309
DCTAuthAccount *existingAccount = [manager accountForProvider:providerName];
310-
NSString *clientID = ((DCTOAuth2Credential *) existingAccount).clientID;
310+
NSString *clientID = ([providerName isEqualToString:@"google"]) ? ((DCTOAuth2Credential *) existingAccount).clientID : (NSString *)nil;
311+
311312
if (([providerName isEqualToString:@"google"] && existingAccount && clientID != nil)
312313
|| (![providerName isEqualToString:@"google"] && existingAccount != nil)) {
313314
if ([existingAccount isAuthorized]) {

0 commit comments

Comments
 (0)