Skip to content

Commit e5d4156

Browse files
authored
Merge pull request #108 from iamham/patch-1
#84 Add idToken to credentials, use GSON to parse accessToken param
2 parents c945970 + 2a1c0fb commit e5d4156

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

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

+15-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import android.support.annotation.Nullable;
77
import android.util.Log;
88

9+
import com.google.gson.Gson;
10+
911
import com.facebook.react.bridge.Arguments;
1012
import com.facebook.react.bridge.Callback;
1113
import com.facebook.react.bridge.ReactApplicationContext;
@@ -398,15 +400,17 @@ private WritableMap accessTokenResponse(
398400
) {
399401
WritableMap resp = Arguments.createMap();
400402
WritableMap response = Arguments.createMap();
403+
Map accessTokenMap = new Gson().fromJson(accessToken.getRawResponse(), Map.class);
401404

402405
Log.d(TAG, "Credential raw response: " + accessToken.getRawResponse());
403-
406+
404407
resp.putString("status", "ok");
405408
resp.putBoolean("authorized", true);
406409
resp.putString("provider", providerName);
407-
response.putString("uuid", accessToken.getParameter("user_id"));
410+
String uuid = (String) accessTokenMap.get("user_id");
411+
response.putString("uuid", uuid);
408412

409-
String tokenType = accessToken.getParameter("token_type");
413+
String tokenType = (String) accessTokenMap.get("token_type");
410414
if (tokenType == null) {
411415
tokenType = "Bearer";
412416
}
@@ -434,24 +438,26 @@ private WritableMap accessTokenResponse(
434438
) {
435439
WritableMap resp = Arguments.createMap();
436440
WritableMap response = Arguments.createMap();
441+
Map accessTokenMap = new Gson().fromJson(accessToken.getRawResponse(), Map.class);
437442

438443
resp.putString("status", "ok");
439444
resp.putBoolean("authorized", true);
440445
resp.putString("provider", providerName);
441446
try {
442-
response.putString("uuid", accessToken.getParameter("user_id"));
447+
String uuid = (String) accessTokenMap.get("user_id");
448+
response.putString("uuid", uuid);
443449
} catch (Exception ex) {
444450
Log.e(TAG, "Exception while getting the access token");
445451
ex.printStackTrace();
446452
}
447453

448454
WritableMap credentials = Arguments.createMap();
449455
Log.d(TAG, "Credential raw response: " + accessToken.getRawResponse());
450-
456+
451457
credentials.putString("accessToken", accessToken.getAccessToken());
452458
String authHeader;
453459

454-
String tokenType = accessToken.getParameter("token_type");
460+
String tokenType = (String) accessTokenMap.get("token_type");
455461
if (tokenType == null) {
456462
tokenType = "Bearer";
457463
}
@@ -462,12 +468,14 @@ private WritableMap accessTokenResponse(
462468
}
463469

464470
String clientID = (String) cfg.get("client_id");
471+
String idToken = (String) accessTokenMap.get("id_token");
465472

466473
authHeader = tokenType + " " + accessToken.getAccessToken();
467474
credentials.putString("authorizationHeader", authHeader);
468475
credentials.putString("type", tokenType);
469476
credentials.putString("scopes", scope);
470477
credentials.putString("clientID", clientID);
478+
credentials.putString("idToken", idToken);
471479
response.putMap("credentials", credentials);
472480

473481
resp.putMap("response", response);
@@ -551,4 +559,4 @@ public static List<Object> recursivelyDeconstructReadableArray(ReadableArray rea
551559
}
552560
return deconstructedList;
553561
}
554-
}
562+
}

0 commit comments

Comments
 (0)