Skip to content

#84 Add idToken to credentials, use GSON to parse accessToken param #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions android/src/main/java/io/fullstack/oauth/OAuthManagerModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.List;
import java.util.ArrayList;

import com.google.gson.Gson;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
Expand Down Expand Up @@ -417,15 +419,17 @@ private WritableMap accessTokenResponse(
) {
WritableMap resp = Arguments.createMap();
WritableMap response = Arguments.createMap();
Map accessTokenMap = new Gson().fromJson(accessToken.getRawResponse(), Map.class);

Log.d(TAG, "Credential raw response: " + accessToken.getRawResponse());

resp.putString("status", "ok");
resp.putBoolean("authorized", true);
resp.putString("provider", providerName);
response.putString("uuid", accessToken.getParameter("user_id"));
String uuid = (String) accessTokenMap.get("user_id");
response.putString("uuid", uuid);

String tokenType = accessToken.getParameter("token_type");
String tokenType = (String) accessTokenMap.get("token_type");
if (tokenType == null) {
tokenType = "Bearer";
}
Expand Down Expand Up @@ -453,24 +457,26 @@ private WritableMap accessTokenResponse(
) {
WritableMap resp = Arguments.createMap();
WritableMap response = Arguments.createMap();
Map accessTokenMap = new Gson().fromJson(accessToken.getRawResponse(), Map.class);

resp.putString("status", "ok");
resp.putBoolean("authorized", true);
resp.putString("provider", providerName);
try {
response.putString("uuid", accessToken.getParameter("user_id"));
String uuid = (String) accessTokenMap.get("user_id");
response.putString("uuid", uuid);
} catch (Exception ex) {
Log.e(TAG, "Exception while getting the access token");
ex.printStackTrace();
}

WritableMap credentials = Arguments.createMap();
Log.d(TAG, "Credential raw response: " + accessToken.getRawResponse());

credentials.putString("accessToken", accessToken.getAccessToken());
String authHeader;

String tokenType = accessToken.getParameter("token_type");
String tokenType = (String) accessTokenMap.get("token_type");
if (tokenType == null) {
tokenType = "Bearer";
}
Expand All @@ -481,12 +487,14 @@ private WritableMap accessTokenResponse(
}

String clientID = (String) cfg.get("client_id");
String idToken = (String) accessTokenMap.get("id_token");

authHeader = tokenType + " " + accessToken.getAccessToken();
credentials.putString("authorizationHeader", authHeader);
credentials.putString("type", tokenType);
credentials.putString("scopes", scope);
credentials.putString("clientID", clientID);
credentials.putString("idToken", idToken);
response.putMap("credentials", credentials);

resp.putMap("response", response);
Expand Down Expand Up @@ -570,4 +578,4 @@ public static List<Object> recursivelyDeconstructReadableArray(ReadableArray rea
}
return deconstructedList;
}
}
}