Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #197 from artsy/authentication
Browse files Browse the repository at this point in the history
[Relay] Add user authentication support.
  • Loading branch information
sarahscott authored Jul 7, 2016
2 parents 8697b65 + e05a8cb commit abd157b
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 180 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ playground.xcworkspace
node_modules
Example/Pods
Example/compile_commands.json
Example/Emission/Configuration.h
2 changes: 2 additions & 0 deletions Example/Emission.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
510E94FC1CCA828900BDF098 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
510E95131CCEB84F00BDF098 /* TestHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestHelper.m; sourceTree = "<group>"; };
510E95151CCEC22C00BDF098 /* TestHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TestHelper.h; sourceTree = "<group>"; };
51E682F51D2DAE24008BC152 /* Configuration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Configuration.h; sourceTree = "<group>"; };
51F3E9A21CF3B8A4004A2013 /* RotationNavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RotationNavigationController.h; sourceTree = "<group>"; };
51F3E9A31CF3B8A4004A2013 /* RotationNavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RotationNavigationController.m; sourceTree = "<group>"; };
77CEB1618D840E2C430A8D7A /* libPods-Emission.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Emission.a"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -98,6 +99,7 @@
isa = PBXGroup;
children = (
510E94FB1CCA828900BDF098 /* LaunchScreen.xib */,
51E682F51D2DAE24008BC152 /* Configuration.h */,
510DCB131CCA69EC0075E8CB /* AppDelegate.h */,
510DCB141CCA69EC0075E8CB /* AppDelegate.m */,
510DCB1C1CCA69EC0075E8CB /* Assets.xcassets */,
Expand Down
8 changes: 5 additions & 3 deletions Example/Emission/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#import "AppDelegate.h"
#import "RotationNavigationController.h"

#import "Configuration.h"

#import <Emission/AREmission.h>
#import <Emission/ARArtistComponentViewController.h>
#import <Emission/ARHomeComponentViewController.h>
Expand Down Expand Up @@ -54,11 +56,11 @@ - (void)setupEmission;
AREmission *emission = nil;
#ifdef ENABLE_DEV_MODE
NSURL *packagerURL = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
emission = [[AREmission alloc] initWithPackagerURL:packagerURL];
[AREmission setSharedInstance:emission];
emission = [[AREmission alloc] initWithAuthenticationToken:OAUTH_TOKEN packagerURL:packagerURL];
#else
emission = [AREmission sharedInstance];
emission = [[AREmission alloc] initWithAuthenticationToken:OAUTH_TOKEN];
#endif
[AREmission setSharedInstance:emission];

emission.APIModule.artistFollowStatusProvider = ^(NSString *artistID, RCTResponseSenderBlock block) {
NSNumber *following = @(randomBOOL());
Expand Down
8 changes: 8 additions & 0 deletions Example/Emission/Configuration.h.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// As per the Artsy API docs at https://developers.artsy.net/docs/authentication, generate a OAuth token for your user
// account with the following command:
//
// $ curl -X POST "https://api.artsy.net/oauth2/access_token?client_id=e750db60ac506978fc70&client_secret=3a33d2085cbd1176153f99781bbce7c6&grant_type=credentials&scope=offline_access&email=...&password=..."
//
// (The client ID & secret are of Eigen OSS: https://github.com/artsy/eigen/blob/0e193d1b/Makefile#L36-L37)

#define OAUTH_TOKEN @"token goes here"
5 changes: 4 additions & 1 deletion Pod/Classes/Core/AREmission.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ NS_ASSUME_NONNULL_BEGIN
+ (instancetype)sharedInstance;
+ (void)setSharedInstance:(AREmission *)instance;

- (instancetype)initWithPackagerURL:(nullable NSURL *)packagerURL NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithAuthenticationToken:(NSString *)authenticationToken;
- (instancetype)initWithAuthenticationToken:(NSString *)authenticationToken packagerURL:(nullable NSURL *)packagerURL NS_DESIGNATED_INITIALIZER;

- (instancetype)init NS_UNAVAILABLE;

@end

Expand Down
42 changes: 32 additions & 10 deletions Pod/Classes/Core/AREmission.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@
#import "ARTemporaryAPIModule.h"

#import <React/RCTBridge.h>
#import <React/RCTBridgeModule.h>


@interface AREmissionConfiguration : NSObject <RCTBridgeModule>
@property (nonatomic, strong, readwrite) NSString *authenticationToken;
@end

@implementation AREmissionConfiguration

RCT_EXPORT_MODULE(Emission);

- (NSDictionary *)constantsToExport
{
return @{ @"authenticationToken": self.authenticationToken };
}

@end


@interface AREmission ()
@property (nonatomic, strong, readwrite) AREmissionConfiguration *configurationModule;
@end

@implementation AREmission

Expand All @@ -16,29 +38,29 @@ + (void)setSharedInstance:(AREmission *)instance;

+ (instancetype)sharedInstance;
{
if (_sharedInstance == nil) {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedInstance = [self new];
});
}
NSParameterAssert(_sharedInstance);
return _sharedInstance;
}

- (instancetype)init;
- (instancetype)initWithAuthenticationToken:(NSString *)authenticationToken;
{
return [self initWithPackagerURL:nil];
return [self initWithAuthenticationToken:authenticationToken packagerURL:nil];
}

- (instancetype)initWithPackagerURL:(NSURL *)packagerURL;
- (instancetype)initWithAuthenticationToken:(NSString *)authenticationToken packagerURL:(NSURL *)packagerURL;
{
if ((self = [super init])) {
_eventsModule = [AREventsModule new];
_switchBoardModule = [ARSwitchBoardModule new];
_APIModule = [ARTemporaryAPIModule new];

_configurationModule = [AREmissionConfiguration new];
_configurationModule.authenticationToken = authenticationToken;

NSArray *modules = @[_APIModule, _configurationModule, _eventsModule, _switchBoardModule];

_bridge = [[RCTBridge alloc] initWithBundleURL:(packagerURL ?: self.releaseBundleURL)
moduleProvider:^{ return @[_eventsModule, _switchBoardModule, _APIModule]; }
moduleProvider:^{ return modules; }
launchOptions:nil];
}
return self;
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@
* `$ brew link pcre`
* `$ brew install watchman --HEAD`
3. Install NPM modules: `$ npm install`
4. Install Pods: `cd Example && pod install`
4. Install Pods: `$ cd Example && pod install`
5. Configure secrets:
* Copy configuration file: `$ cd Example/Emission && cp Configuration.h.sample Configuration.h`
* Edit the configuration file as per the instructions inside.

### Development

1. Run `$ npm start` from the top directory, which will:
- Clean the example app’s Xcode build dir.
- Start the example app’s React Native packager.
* Clean the example app’s Xcode build dir.
* Start the example app’s React Native packager.

2. Now from Xcode you can run the app in `Example/Emission.xcworkspace`.

3. We vendor some data from other repositories that you will sometimes need to update. You can either update all of them
with `$ npm run sync-externals` or individually:
- The GraphQL schema of metaphysics that Relay uses to generate queries from: `$ npm run sync-schema`
- The colors defined in Artsy’s style-guide: `$ npm run sync-colors`
* The GraphQL schema of metaphysics that Relay uses to generate queries from: `$ npm run sync-schema`
* The colors defined in Artsy’s style-guide: `$ npm run sync-colors`

### Using Relay

Expand Down
Loading

0 comments on commit abd157b

Please sign in to comment.