Skip to content

Commit

Permalink
Merge fullstackreact/react-native-oauth master branch into shalin-jas…
Browse files Browse the repository at this point in the history
…ani/fullstackreact/react-native-oauth master branch (#1)

* Added fullstackreact#171
and my NSString *clientID fix, which might not be as good as
https://github.com/fullstackreact/react-native-oauth/blob/2f8c8d1483526bbc8a6ca72183c6d11a71538ad3/ios/OAuthManager/OAuthManager.m

* Added fullstackreact#171
and my NSString *clientID fix, which might not be as good as
https://github.com/fullstackreact/react-native-oauth/blob/2f8c8d1483526bbc8a6ca72183c6d11a71538ad3/ios/OAuthManager/OAuthManager.m

* Added fullstackreact#171
and my NSString *clientID fix, which might not be as good as
https://github.com/fullstackreact/react-native-oauth/blob/2f8c8d1483526bbc8a6ca72183c6d11a71538ad3/ios/OAuthManager/OAuthManager.m

* Merge PR 121, fix user agent, fix full screen webview

* Changed if/else statement to avoid React error.

* Fix duplicate RCTMethodInfo import (facebook/react-native#15775) (zoontek/react-native-permissions#137)

* Fix duplicate React library import error conflict w/certain pods

* Pass back response headers over javascript bridge

* Dispatch safariViewController on main queue

The safariViewController dispatch was occuring on another thread.
This sometimes caused app crashes when the view was presented,
in particular if the keyboard had been presented via a TextInput or
other component. The resulting crash complained about
_cachedSystemAnimationFence and the main thread. This has been with
other React Native apps that load a viewController.

Dispatching to present the viewController on the main thread fixes this
issue.

* Fix build issue

* Remove deprecated @OverRide

* Fix: Duplicate RCTMethodInfo while building iOS app

* Fix error for redefinition of RCTMethodInfo

* Ignored dist/

* 2.1.16

* 2.1.17

* 2.1.18
  • Loading branch information
shalin-jasani committed Sep 10, 2018
1 parent ad01a3e commit 6e4a1c4
Show file tree
Hide file tree
Showing 10 changed files with 861 additions and 38 deletions.
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["env"],
"plugins": ["transform-async-to-generator", "transform-object-rest-spread"]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ xcuserdata/
.idea
.vscode
javac-services.0.log*
dist/
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
mWebView.setVisibility(View.VISIBLE);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setUserAgentString("Mozilla/5.0 Google");


LayoutParams layoutParams = this.getFullscreenLayoutParams(context);
Expand Down Expand Up @@ -172,7 +171,7 @@ private LayoutParams getFullscreenLayoutParams(Context context) {
realHeight = display.getHeight();
}

return new LayoutParams(realWidth, realHeight-convertDpToPixel(50f,context));
return new LayoutParams(realWidth, realHeight);
}


Expand Down
45 changes: 29 additions & 16 deletions 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 @@ -400,18 +401,36 @@ 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());


/* 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);
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 oauthTokenSecret = (String) accessToken.getParameter("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 +441,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 +458,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 +483,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 @@ -22,7 +22,6 @@ public OAuthManagerPackage() {
* @param reactContext react application context that can be used to create modules
* @return list of native modules to register with the newly created catalyst instance
*/
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new OAuthManagerModule(reactContext));
Expand All @@ -45,7 +44,6 @@ public List<Class<? extends JavaScriptModule>> createJSModules() {
* @param reactContext
* @return a list of view managers that should be registered with {@link UIManagerModule}
*/
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +268,11 @@ private static ServiceBuilder _oauth2ServiceBuilder(
builder.scope(scopeStr);
}

boolean rawScopes = (cfg.containsKey("rawScopes") && ((String)cfg.get("rawScopes")).equalsIgnoreCase("true"));

if (opts != null && opts.hasKey("scopes")) {
scopes = (String) opts.getString("scopes");
String scopeStr = null;

if (!rawScopes)
scopeStr = OAuthManagerProviders.getScopeString(scopes, ",");
else
scopeStr = scopes;

String scopeStr = OAuthManagerProviders.getScopeString(scopes, ",");
builder.scope(scopeStr);
}
}

if (callbackUrl != null) {
builder.callback(callbackUrl);
Expand Down
6 changes: 3 additions & 3 deletions ios/OAuthManager/OAuthManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#import "RCTBridgeModule.h"
#endif

#if __has_include("RCTLinkingManager.h")
#import "RCTLinkingManager.h"
#else
#if __has_include(<React/RCTLinkingManager.h>)
#import <React/RCTLinkingManager.h>
#else
#import "RCTLinkingManager.h"
#endif


Expand Down
14 changes: 11 additions & 3 deletions ios/OAuthManager/OAuthManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ + (BOOL)setupOAuthHandler:(UIApplication *)application
dispatch_async(dispatch_get_main_queue(), ^{
safariViewController = [[SFSafariViewController alloc] initWithURL:URL];
UIViewController *viewController = application.keyWindow.rootViewController;
[viewController presentViewController:safariViewController animated:YES completion: nil];
dispatch_async(dispatch_get_main_queue(), ^{
[viewController presentViewController:safariViewController animated:YES completion: nil];
});
});
} else {
[application openURL:URL];
Expand Down Expand Up @@ -305,7 +307,8 @@ - (NSDictionary *) getConfigForProvider:(NSString *)name
NSMutableDictionary *cfg = [[manager getConfigForProvider:providerName] mutableCopy];

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 Expand Up @@ -488,9 +491,12 @@ - (NSDictionary *) getConfigForProvider:(NSString *)name
} else {
NSInteger statusCode = response.statusCode;
NSData *rawData = response.data;
NSDictionary *headers = response.HTTPHeaders;

NSError *err;
NSArray *data;



// Check if returned data is a valid JSON
// != nil returned if the rawdata is not a valid JSON
Expand All @@ -512,9 +518,11 @@ - (NSDictionary *) getConfigForProvider:(NSString *)name
};
callback(@[errResp]);
} else {

NSDictionary *resp = @{
@"status": @(statusCode),
@"data": data != nil ? data : @[]
@"data": data != nil ? data : @[],
@"headers": headers,
};
callback(@[[NSNull null], resp]);
}
Expand Down
Loading

0 comments on commit 6e4a1c4

Please sign in to comment.