Skip to content
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

Merge fullstackreact/react-native-oauth master branch into shalin-jasani/fullstackreact/react-native-oauth master branch #1

Merged
merged 28 commits into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6925880
Added https://github.com/fullstackreact/react-native-oauth/pull/171
SailingSteve Oct 25, 2017
9c68923
Added https://github.com/fullstackreact/react-native-oauth/pull/171
SailingSteve Oct 25, 2017
370c065
Added https://github.com/fullstackreact/react-native-oauth/pull/171
SailingSteve Oct 26, 2017
0b8b674
Merge PR 121, fix user agent, fix full screen webview
Nov 24, 2017
28f914d
Changed if/else statement to avoid React error.
compulsor Mar 19, 2018
02c6c1d
Fix duplicate RCTMethodInfo import (https://github.com/facebook/react…
thebradbain Apr 7, 2018
3949c3b
Fix duplicate React library import error conflict w/certain pods
thebradbain Apr 28, 2018
aa32136
Pass back response headers over javascript bridge
thebradbain Apr 28, 2018
2d53534
Merge branch 'master' of https://github.com/fullstackreact/react-nati…
thebradbain Apr 30, 2018
aa31836
Dispatch safariViewController on main queue
stonehippo May 8, 2018
b311024
Fix build issue
stonehippo May 8, 2018
84517e0
Remove deprecated @Override
rgabs May 10, 2018
f1de1ef
Fix: Duplicate RCTMethodInfo while building iOS app
rgabs May 11, 2018
234cf6f
Fix error for redefinition of RCTMethodInfo
madana-i Jun 3, 2018
87c0fe9
Merge pull request #213 from DaikiInaba/master
auser Jul 29, 2018
fbabfbb
Merge pull request #209 from rgabs/patch-2
auser Jul 29, 2018
786009f
Merge pull request #208 from rgabs/patch-1
auser Jul 29, 2018
92c81ee
Ignored dist/
Jul 29, 2018
0054354
2.1.16
Jul 29, 2018
ae28d03
Merge pull request #207 from stonehippo/master
auser Jul 29, 2018
4e0f4e3
Merge branch 'master' of github.com:fullstackreact/react-native-oauth
Jul 29, 2018
72acd19
Updates
Jul 29, 2018
e7ac4a8
Merge pull request #203 from Compulsor/master
auser Jul 29, 2018
87786d6
Merge pull request #182 from SailingSteve/master
auser Jul 29, 2018
897ba2e
Merge branch 'master' into master
auser Jul 29, 2018
f1015c2
Merge pull request #180 from matiere-noire/master
auser Jul 29, 2018
0b6d001
2.1.17
Jul 29, 2018
afaffc9
2.1.18
Jul 29, 2018
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
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
12 changes: 6 additions & 6 deletions ios/OAuthManager/OAuthManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

#import <Foundation/Foundation.h>

#if __has_include("RCTBridgeModule.h")
#import "RCTBridgeModule.h"
#else
#if __has_include(<React/RCTBridgeModule.h>)
#import <React/RCTBridgeModule.h>
#else
#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