Skip to content

Commit

Permalink
[ios][home] remove deprecated client-side authentication checks for o…
Browse files Browse the repository at this point in the history
…pening projects
  • Loading branch information
esamelson committed Feb 1, 2019
1 parent 00b3eb3 commit 4d0e080
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 95 deletions.
36 changes: 0 additions & 36 deletions home/HomeApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import MenuView from './menu/MenuView';
import Store from './redux/Store';

import addListenerWithNativeCallback from './utils/addListenerWithNativeCallback';
import getViewerUsernameAsync from './utils/getViewerUsernameAsync';

function cacheImages(images) {
return images.map(image => Asset.fromModule(image).downloadAsync());
Expand All @@ -32,10 +31,6 @@ export default class App extends React.Component {

componentDidMount() {
this._initializeStateAsync();
addListenerWithNativeCallback(
'ExponentKernel.getIsValidHomeManifestToOpen',
this._getIsValidHomeManifestToOpen
);
}

_isExpoHost = host => {
Expand Down Expand Up @@ -63,37 +58,6 @@ export default class App extends React.Component {
return !this._isExpoHost(host);
};

_getIsValidHomeManifestToOpen = async event => {
const { manifest, manifestUrl } = event;
let isValid = false;
if (!Constants.isDevice) {
// simulator has no restriction
isValid = true;
} else if (this._isThirdPartyHosted(manifestUrl)) {
// TODO(quin): figure out a long term solution for this
// allow self hosted applications to be loaded into the client
isValid = true;
} else if (manifest) {
if (manifest.developer && manifest.developer.tool) {
isValid = true;
} else if (manifest.slug === 'snack') {
isValid = true;
} else if (manifest.id) {
try {
let manifestAuthorComponents = manifest.id.split('/');
let manifestAuthor = manifestAuthorComponents[0].substring(1);

let username = await getViewerUsernameAsync();

if (username && manifestAuthor && manifestAuthor === username) {
isValid = true;
}
} catch (_) {}
}
}
return { isValid };
};

_initializeStateAsync = async () => {
try {
Store.dispatch(SettingsActions.loadSettings());
Expand Down
1 change: 0 additions & 1 deletion ios/Client/EXHomeAppManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ FOUNDATION_EXPORT NSString *kEXHomeManifestResourceName;
- (void)addHistoryItemWithUrl:(NSURL *)manifestUrl manifest:(NSDictionary *)manifest;
- (void)getHistoryUrlForExperienceId:(NSString *)experienceId completion:(void (^)(NSString *))completion;
- (void)showQRReader;
- (void)getIsValidHomeManifestToOpen:(NSDictionary *)manifest manifestUrl:(NSURL *) manifestUrl completion:(void (^)(BOOL isValid))completion;

@end
12 changes: 0 additions & 12 deletions ios/Client/EXHomeAppManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,6 @@ - (void)getHistoryUrlForExperienceId:(NSString *)experienceId completion:(void (
}];
}

- (void)getIsValidHomeManifestToOpen:(NSDictionary *)manifest manifestUrl:(NSURL *) manifestUrl completion:(void (^)(BOOL))completion
{
[self _dispatchHomeJSEvent:@"getIsValidHomeManifestToOpen"
body:@{ @"manifest": manifest, @"manifestUrl": manifestUrl.absoluteString }
onSuccess:^(NSDictionary *result) {
BOOL isValid = [result[@"isValid"] boolValue];
completion(isValid);
} onFailure:^(NSString *errorMessage) {
completion(NO);
}];
}

- (void)showQRReader
{
[self _dispatchHomeJSEvent:@"showQRReader" body:@{} onSuccess:nil onFailure:nil];
Expand Down
5 changes: 0 additions & 5 deletions ios/Client/EXRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,6 @@ - (void)addHistoryItemWithUrl:(NSURL *)manifestUrl manifest:(NSDictionary *)mani
[[self _getHomeAppManager] addHistoryItemWithUrl:manifestUrl manifest:manifest];
}

- (void)getIsValidHomeManifestToOpen:(NSDictionary *)manifest manifestUrl:(NSURL *) manifestUrl completion:(void (^)(BOOL isValid))completion
{
[[self _getHomeAppManager] getIsValidHomeManifestToOpen:manifest manifestUrl:(NSURL *) manifestUrl completion:completion];
}

- (void)getHistoryUrlForExperienceId:(NSString *)experienceId completion:(void (^)(NSString *))completion
{
return [[self _getHomeAppManager] getHistoryUrlForExperienceId:experienceId completion:completion];
Expand Down
1 change: 0 additions & 1 deletion ios/Exponent/Kernel/Core/EXAppBrowserController.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ NS_ASSUME_NONNULL_BEGIN
- (void)showQRReader;
- (void)addHistoryItemWithUrl:(NSURL *)manifestUrl manifest:(NSDictionary *)manifest;
- (void)getHistoryUrlForExperienceId:(NSString *)experienceId completion:(void (^)(NSString * _Nullable))completion;
- (void)getIsValidHomeManifestToOpen:(NSDictionary *)manifest manifestUrl:(NSURL *) manifestUrl completion:(void (^)(BOOL isValid))completion;
- (BOOL)isNuxFinished;
- (void)setIsNuxFinished:(BOOL)isFinished;
- (void)appDidFinishLoadingSuccessfully:(EXKernelAppRecord *)appRecord;
Expand Down
1 change: 0 additions & 1 deletion ios/Exponent/Kernel/Core/EXKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
NS_ASSUME_NONNULL_BEGIN

FOUNDATION_EXPORT NSString *kEXKernelErrorDomain;
FOUNDATION_EXPORT const NSUInteger kEXErrorCodeAppForbidden;

typedef NS_ENUM(NSInteger, EXKernelErrorCode) {
EXKernelErrorCodeModuleDeallocated,
Expand Down
2 changes: 0 additions & 2 deletions ios/Exponent/Kernel/Core/EXKernel.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
NSString * const kEXDeviceInstallUUIDKey = @"EXDeviceInstallUUIDKey";
NSString * const kEXKernelClearJSCacheUserDefaultsKey = @"EXKernelClearJSCacheUserDefaultsKey";

const NSUInteger kEXErrorCodeAppForbidden = 424242;

@interface EXKernel () <EXKernelAppRegistryDelegate>

@end
Expand Down
43 changes: 8 additions & 35 deletions ios/Exponent/Kernel/Views/EXAppViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,10 @@ - (void)backgroundControllers

- (void)appLoader:(EXAppLoader *)appLoader didLoadOptimisticManifest:(NSDictionary *)manifest
{
[self _whenManifestIsValidToOpen:manifest manifestUrl:appLoader.manifestUrl performBlock:^{
if ([EXKernel sharedInstance].browserController) {
[[EXKernel sharedInstance].browserController addHistoryItemWithUrl:appLoader.manifestUrl manifest:manifest];
}
[self _rebuildBridgeWithLoadingViewManifest:manifest];
}];
if ([EXKernel sharedInstance].browserController) {
[[EXKernel sharedInstance].browserController addHistoryItemWithUrl:appLoader.manifestUrl manifest:manifest];
}
[self _rebuildBridgeWithLoadingViewManifest:manifest];
}

- (void)appLoader:(EXAppLoader *)appLoader didLoadBundleWithProgress:(EXLoadingProgress *)progress
Expand All @@ -236,12 +234,10 @@ - (void)appLoader:(EXAppLoader *)appLoader didLoadBundleWithProgress:(EXLoadingP

- (void)appLoader:(EXAppLoader *)appLoader didFinishLoadingManifest:(NSDictionary *)manifest bundle:(NSData *)data
{
[self _whenManifestIsValidToOpen:manifest manifestUrl:appLoader.manifestUrl performBlock:^{
[self _rebuildBridgeWithLoadingViewManifest:manifest];
if (self->_appRecord.appManager.status == kEXReactAppManagerStatusBridgeLoading) {
[self->_appRecord.appManager appLoaderFinished];
}
}];
[self _rebuildBridgeWithLoadingViewManifest:manifest];
if (self->_appRecord.appManager.status == kEXReactAppManagerStatusBridgeLoading) {
[self->_appRecord.appManager appLoaderFinished];
}
}

- (void)appLoader:(EXAppLoader *)appLoader didFailWithError:(NSError *)error
Expand Down Expand Up @@ -430,9 +426,6 @@ - (void)setIsLoading:(BOOL)isLoading

- (BOOL)_willAutoRecoverFromError:(NSError *)error
{
if (error.code == kEXErrorCodeAppForbidden) {
return NO;
}
if (![_appRecord.appManager enablesDeveloperTools]) {
BOOL shouldRecover = [[EXKernel sharedInstance].serviceRegistry.errorRecoveryManager experienceIdShouldReloadOnError:_appRecord.experienceId];
if (shouldRecover) {
Expand All @@ -456,26 +449,6 @@ - (void)_invalidateRecoveryTimer
}
}

// this is deprecated in favor of the server side check
// TODO(eric): remove
- (void)_whenManifestIsValidToOpen:(NSDictionary *)manifest manifestUrl:(NSURL *) manifestUrl performBlock:(void (^)(void))block
{
if (self.appRecord.appManager.requiresValidManifests && [EXKernel sharedInstance].browserController) {
[[EXKernel sharedInstance].browserController getIsValidHomeManifestToOpen:manifest manifestUrl:manifestUrl completion:^(BOOL isValid) {
if (isValid) {
block();
} else {
[self appLoader:self->_appRecord.appLoader didFailWithError:[NSError errorWithDomain:EXNetworkErrorDomain
code:kEXErrorCodeAppForbidden
userInfo:@{ NSLocalizedDescriptionKey: @"Expo Client can only be used to view your own projects. To view this project, please ensure you are signed in to the same Expo account that created it." }]];
}
}];
} else {
// no browser present, everything is valid
block();
}
}

@end

NS_ASSUME_NONNULL_END
2 changes: 0 additions & 2 deletions ios/Exponent/Kernel/Views/EXErrorView.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ - (void)setType:(EXFatalErrorType)type
_lblError.text = [NSString stringWithFormat:@"There was a problem loading %@.", appOwnerName];
if (_error.code == kCFURLErrorNotConnectedToInternet) {
_lblError.text = [NSString stringWithFormat:@"%@ Make sure you're connected to the internet.", _lblError.text];
} else if (_error.code == kEXErrorCodeAppForbidden) {
_lblError.text = [NSString stringWithFormat:@"Sorry, you are not allowed to load %@.", appOwnerName];
} else if (_appRecord.appLoader.manifestUrl) {
NSString *url = _appRecord.appLoader.manifestUrl.absoluteString;
if ([self _urlLooksLikeLAN:url]) {
Expand Down

0 comments on commit 4d0e080

Please sign in to comment.