Skip to content

Commit 2a1c0fb

Browse files
authored
Add idToken to credentials, use GSON to parse accessToken param
- Add idToken to the credentials obj - Use GSON to parse accessToken rawResponse instead of using getParameter (On Google response its response as JSON which getParameter unable to parse it so I use GSON instead, is all the raw response JSON ?)
1 parent 99d833b commit 2a1c0fb

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.List;
2424
import java.util.ArrayList;
2525

26+
import com.google.gson.Gson;
27+
2628
import com.facebook.react.bridge.Arguments;
2729
import com.facebook.react.bridge.LifecycleEventListener;
2830
import com.facebook.react.bridge.ReactApplicationContext;
@@ -417,15 +419,17 @@ private WritableMap accessTokenResponse(
417419
) {
418420
WritableMap resp = Arguments.createMap();
419421
WritableMap response = Arguments.createMap();
422+
Map accessTokenMap = new Gson().fromJson(accessToken.getRawResponse(), Map.class);
420423

421424
Log.d(TAG, "Credential raw response: " + accessToken.getRawResponse());
422-
425+
423426
resp.putString("status", "ok");
424427
resp.putBoolean("authorized", true);
425428
resp.putString("provider", providerName);
426-
response.putString("uuid", accessToken.getParameter("user_id"));
429+
String uuid = (String) accessTokenMap.get("user_id");
430+
response.putString("uuid", uuid);
427431

428-
String tokenType = accessToken.getParameter("token_type");
432+
String tokenType = (String) accessTokenMap.get("token_type");
429433
if (tokenType == null) {
430434
tokenType = "Bearer";
431435
}
@@ -453,24 +457,26 @@ private WritableMap accessTokenResponse(
453457
) {
454458
WritableMap resp = Arguments.createMap();
455459
WritableMap response = Arguments.createMap();
460+
Map accessTokenMap = new Gson().fromJson(accessToken.getRawResponse(), Map.class);
456461

457462
resp.putString("status", "ok");
458463
resp.putBoolean("authorized", true);
459464
resp.putString("provider", providerName);
460465
try {
461-
response.putString("uuid", accessToken.getParameter("user_id"));
466+
String uuid = (String) accessTokenMap.get("user_id");
467+
response.putString("uuid", uuid);
462468
} catch (Exception ex) {
463469
Log.e(TAG, "Exception while getting the access token");
464470
ex.printStackTrace();
465471
}
466472

467473
WritableMap credentials = Arguments.createMap();
468474
Log.d(TAG, "Credential raw response: " + accessToken.getRawResponse());
469-
475+
470476
credentials.putString("accessToken", accessToken.getAccessToken());
471477
String authHeader;
472478

473-
String tokenType = accessToken.getParameter("token_type");
479+
String tokenType = (String) accessTokenMap.get("token_type");
474480
if (tokenType == null) {
475481
tokenType = "Bearer";
476482
}
@@ -481,12 +487,14 @@ private WritableMap accessTokenResponse(
481487
}
482488

483489
String clientID = (String) cfg.get("client_id");
490+
String idToken = (String) accessTokenMap.get("id_token");
484491

485492
authHeader = tokenType + " " + accessToken.getAccessToken();
486493
credentials.putString("authorizationHeader", authHeader);
487494
credentials.putString("type", tokenType);
488495
credentials.putString("scopes", scope);
489496
credentials.putString("clientID", clientID);
497+
credentials.putString("idToken", idToken);
490498
response.putMap("credentials", credentials);
491499

492500
resp.putMap("response", response);
@@ -570,4 +578,4 @@ public static List<Object> recursivelyDeconstructReadableArray(ReadableArray rea
570578
}
571579
return deconstructedList;
572580
}
573-
}
581+
}

0 commit comments

Comments
 (0)