Skip to content

Fixes for Twitter and Google login on Android #121

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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
24 changes: 8 additions & 16 deletions android/src/main/java/io/fullstack/oauth/OAuthManagerModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import android.support.annotation.Nullable;
import android.util.Log;

import com.google.gson.Gson;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
Expand Down Expand Up @@ -400,18 +398,18 @@ 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);
String uuid = (String) accessTokenMap.get("user_id");

String uuid = accessToken.getParameter("user_id");
response.putString("uuid", uuid);
String oauthTokenSecret = (String) accessTokenMap.get("oauth_token_secret");

String tokenType = (String) accessTokenMap.get("token_type");
String tokenType = (String) accessToken.getParameter("token_type");
if (tokenType == null) {
tokenType = "Bearer";
}
Expand All @@ -422,7 +420,6 @@ private WritableMap accessTokenResponse(
credentials.putString("access_token", accessToken.getToken());
credentials.putString("access_token_secret", oauthTokenSecret);
credentials.putString("type", tokenType);
// credentials.putString("scope", accessToken.getScope());
credentials.putString("consumerKey", consumerKey);

response.putMap("credentials", credentials);
Expand All @@ -440,26 +437,21 @@ 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 {
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();
}

String uuid = accessToken.getParameter("user_id");
response.putString("uuid", uuid);

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

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

String tokenType = (String) accessTokenMap.get("token_type");
String tokenType = accessToken.getTokenType();
if (tokenType == null) {
tokenType = "Bearer";
}
Expand All @@ -470,7 +462,7 @@ private WritableMap accessTokenResponse(
}

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

authHeader = tokenType + " " + accessToken.getAccessToken();
credentials.putString("authorizationHeader", authHeader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private static ServiceBuilder _oauth2ServiceBuilder(
String scopes = "";
if (cfg.containsKey("scopes")) {
scopes = (String) cfg.get("scopes");
String scopeStr = OAuthManagerProviders.getScopeString(scopes, ",");
String scopeStr = OAuthManagerProviders.getScopeString(scopes, " ");
builder.scope(scopeStr);
}

Expand All @@ -278,7 +278,7 @@ private static ServiceBuilder _oauth2ServiceBuilder(
scopeStr = OAuthManagerProviders.getScopeString(scopes, ",");
else
scopeStr = scopes;

builder.scope(scopeStr);
}

Expand All @@ -296,7 +296,7 @@ private static String getScopeString(
final String scopes,
final String joinBy
) {
List<String> array = Arrays.asList(scopes.replaceAll("\\s", "").split("[ ,]+"));
List<String> array = Arrays.asList(scopes.replaceAll("\\s", "").split(","));
Log.d(TAG, "array: " + array + " (" + array.size() + ") from " + scopes);
return TextUtils.join(joinBy, array);
}
Expand Down
2 changes: 1 addition & 1 deletion ios/OAuthManager/OAuth2Client.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ - (DCTOAuth2Account *) getAccount:(NSString *)providerName
NSString *scopeStr = [cfg valueForKey:@"scopes"];
// NSArray *scopes = [scopeStr componentsSeparatedByString:@","];

NSString *sep = @", ";
NSString *sep = @" ";
NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:sep];
NSArray *scopes = [scopeStr componentsSeparatedByCharactersInSet:set];

Expand Down