Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
SailingSteve committed Oct 25, 2017
1 parent 2a1fb1b commit 6925880
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 20 additions & 1 deletion android/src/main/java/io/fullstack/oauth/OAuthManagerModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions ios/OAuthManager/OAuthManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down

0 comments on commit 6925880

Please sign in to comment.