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

Introduce A0Lock class #107

Merged
merged 7 commits into from
May 9, 2015
Merged
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
10 changes: 10 additions & 0 deletions Lock/Lock.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
5F1DA1AB1A7BE0E000E7BA6D /* A0LockConfigurationSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F1DA1AA1A7BE0E000E7BA6D /* A0LockConfigurationSpec.m */; };
5F1DA1AD1A7C093500E7BA6D /* AppInfo.json in Resources */ = {isa = PBXBuildFile; fileRef = 5F1DA1AC1A7C093500E7BA6D /* AppInfo.json */; };
5F22B5D619E84C28002A730A /* A0FilteredConnectionDomainMatcherSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F22B5D519E84C28002A730A /* A0FilteredConnectionDomainMatcherSpec.m */; };
5F22E6ED1AFBC6E80037859D /* A0LockSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F22E6EC1AFBC6E80037859D /* A0LockSpec.m */; };
5F3237351A7A858E00B58994 /* A0AnnotatedRequestSerializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F3237341A7A858E00B58994 /* A0AnnotatedRequestSerializer.m */; };
5F35161619B8CBA500574C11 /* A0UserIdentitySpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F35161519B8CBA500574C11 /* A0UserIdentitySpec.m */; };
5F3A9C561A0D16FF00154DF2 /* Crashlytics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F3A9C541A0D16FF00154DF2 /* Crashlytics.framework */; };
Expand All @@ -25,6 +26,7 @@
5F48BBA81A7B151700D8E05B /* POST-delegation.response in Resources */ = {isa = PBXBuildFile; fileRef = 5F48BBA71A7B151700D8E05B /* POST-delegation.response */; };
5F7112E519D5C18B001971BE /* A0AuthParametersSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F7112E419D5C18B001971BE /* A0AuthParametersSpec.m */; };
5F75E4541A2FB06D00EAB3B7 /* A0APIv1RouterSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F75E4531A2FB06D00EAB3B7 /* A0APIv1RouterSpec.m */; };
5F8D5FD71AFD637B00E9BF55 /* A0LockApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F8D5FD61AFD637B00E9BF55 /* A0LockApplication.m */; };
5F91E66E19E32C48003150DF /* A0ConnectionSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F91E66D19E32C48003150DF /* A0ConnectionSpec.m */; };
5F951A981A0EC7D600D128D0 /* A0HomeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F951A971A0EC7D600D128D0 /* A0HomeViewController.m */; };
5F951ABB1A1189A600D128D0 /* Lock.strings in Resources */ = {isa = PBXBuildFile; fileRef = 5F951ABD1A1189A600D128D0 /* Lock.strings */; };
Expand Down Expand Up @@ -86,6 +88,7 @@
5F1DA1AA1A7BE0E000E7BA6D /* A0LockConfigurationSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = A0LockConfigurationSpec.m; sourceTree = "<group>"; };
5F1DA1AC1A7C093500E7BA6D /* AppInfo.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = AppInfo.json; path = ../AppInfo.json; sourceTree = "<group>"; };
5F22B5D519E84C28002A730A /* A0FilteredConnectionDomainMatcherSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = A0FilteredConnectionDomainMatcherSpec.m; sourceTree = "<group>"; };
5F22E6EC1AFBC6E80037859D /* A0LockSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = A0LockSpec.m; sourceTree = "<group>"; };
5F3237331A7A858E00B58994 /* A0AnnotatedRequestSerializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = A0AnnotatedRequestSerializer.h; path = Utils/A0AnnotatedRequestSerializer.h; sourceTree = "<group>"; };
5F3237341A7A858E00B58994 /* A0AnnotatedRequestSerializer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = A0AnnotatedRequestSerializer.m; path = Utils/A0AnnotatedRequestSerializer.m; sourceTree = "<group>"; };
5F35161519B8CBA500574C11 /* A0UserIdentitySpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = A0UserIdentitySpec.m; sourceTree = "<group>"; };
Expand All @@ -96,6 +99,8 @@
5F48BBA71A7B151700D8E05B /* POST-delegation.response */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "POST-delegation.response"; sourceTree = "<group>"; };
5F7112E419D5C18B001971BE /* A0AuthParametersSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = A0AuthParametersSpec.m; sourceTree = "<group>"; };
5F75E4531A2FB06D00EAB3B7 /* A0APIv1RouterSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = A0APIv1RouterSpec.m; sourceTree = "<group>"; };
5F8D5FD51AFD637B00E9BF55 /* A0LockApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = A0LockApplication.h; sourceTree = "<group>"; };
5F8D5FD61AFD637B00E9BF55 /* A0LockApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = A0LockApplication.m; sourceTree = "<group>"; };
5F91E66D19E32C48003150DF /* A0ConnectionSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = A0ConnectionSpec.m; sourceTree = "<group>"; };
5F951A961A0EC7D600D128D0 /* A0HomeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = A0HomeViewController.h; sourceTree = "<group>"; };
5F951A971A0EC7D600D128D0 /* A0HomeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = A0HomeViewController.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -274,6 +279,8 @@
5FF3B5161A25439400BE84F9 /* A0SettingsViewController.h */,
5FF3B5171A25439400BE84F9 /* A0SettingsViewController.m */,
5FA2CAEA1A7FE673009178C0 /* Launch Screen.xib */,
5F8D5FD51AFD637B00E9BF55 /* A0LockApplication.h */,
5F8D5FD61AFD637B00E9BF55 /* A0LockApplication.m */,
);
path = Lock;
sourceTree = "<group>";
Expand Down Expand Up @@ -315,6 +322,7 @@
5FEDA4B71A1E5DC8009B1C2F /* A0PasswordValidatorSpec.m */,
5FEDA4BC1A1E60F3009B1C2F /* A0ConfirmPasswordValidatorSpec.m */,
5FEDA4C11A1E7589009B1C2F /* A0CredentialsValidatorSpec.m */,
5F22E6EC1AFBC6E80037859D /* A0LockSpec.m */,
);
path = Tests;
sourceTree = "<group>";
Expand Down Expand Up @@ -538,6 +546,7 @@
6003F59E195388D20070C39A /* A0AppDelegate.m in Sources */,
6003F5A7195388D20070C39A /* A0ViewController.m in Sources */,
6003F59A195388D20070C39A /* main.m in Sources */,
5F8D5FD71AFD637B00E9BF55 /* A0LockApplication.m in Sources */,
5F951A981A0EC7D600D128D0 /* A0HomeViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -563,6 +572,7 @@
5FC45F8D1AE5942400427E31 /* A0HTTPStubber.m in Sources */,
5F12365C19675EA9006CE0D2 /* A0ApplicationSpec.m in Sources */,
5F7112E519D5C18B001971BE /* A0AuthParametersSpec.m in Sources */,
5F22E6ED1AFBC6E80037859D /* A0LockSpec.m in Sources */,
5FEDA4BD1A1E60F3009B1C2F /* A0ConfirmPasswordValidatorSpec.m in Sources */,
5F35161619B8CBA500574C11 /* A0UserIdentitySpec.m in Sources */,
5F3237351A7A858E00B58994 /* A0AnnotatedRequestSerializer.m in Sources */,
Expand Down
19 changes: 6 additions & 13 deletions Lock/Lock/A0HomeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#import <SimpleKeychain/A0SimpleKeychain.h>
#import <JWTDecode/A0JWTDecoder.h>
#import <ReactiveCocoa/ReactiveCocoa.h>
#import "A0LockApplication.h"

#define kClientIdKey @"Auth0ClientId"
#define kTenantKey @"Auth0Tenant"
Expand All @@ -42,7 +43,6 @@ static BOOL isRunningTests(void) {
@interface A0HomeViewController ()

@property (strong, nonatomic) A0SimpleKeychain *keychain;

@end

@implementation A0HomeViewController
Expand All @@ -56,23 +56,13 @@ - (void)viewDidLoad {
}
#endif

A0TwitterAuthenticator *twitter = [A0TwitterAuthenticator newAuthenticatorWithKey:@""
andSecret:@""];
A0FacebookAuthenticator *facebook = [A0FacebookAuthenticator newAuthenticatorWithDefaultPermissions];
NSString *googlePlusClientId = [[NSBundle mainBundle] infoDictionary][@"GooglePlusClientId"];
A0GooglePlusAuthenticator *googleplus = [A0GooglePlusAuthenticator newAuthenticatorWithClientId:googlePlusClientId];
[[A0IdentityProviderAuthenticator sharedInstance] registerAuthenticationProviders:@[
twitter,
facebook,
googleplus,
]];

self.keychain = [A0SimpleKeychain keychainWithService:@"Auth0"];
@weakify(self);
NSString* refreshToken = [self.keychain stringForKey: @"refresh_token"];
NSString* idToken = [self.keychain stringForKey: @"id_token"];
A0APIClient *client = [[[A0LockApplication sharedInstance] lock] apiClient];
if (refreshToken) {
[[[A0APIClient sharedClient] fetchNewIdTokenWithRefreshToken:refreshToken parameters:nil] subscribeNext:^(A0Token *token) {
[[client fetchNewIdTokenWithRefreshToken:refreshToken parameters:nil] subscribeNext:^(A0Token *token) {
@strongify(self);
[self.keychain setString:token.idToken forKey:@"id_token"];
[self performSegueWithIdentifier:@"LoggedIn" sender:self];
Expand All @@ -93,6 +83,7 @@ - (void)loginNative:(id)sender {
[self.keychain clearAll];
A0LockViewController *controller = [[A0LockViewController alloc] init];
@weakify(self);
controller.lock = [[A0LockApplication sharedInstance] lock];
controller.closable = YES;
controller.loginAfterSignUp = YES;
controller.usesEmail = YES;
Expand All @@ -113,6 +104,7 @@ - (void)loginTouchID:(id)sender {
[self.keychain clearAll];
A0TouchIDLockViewController *controller = [[A0TouchIDLockViewController alloc] init];
controller.closable = YES;
controller.lock = [[A0LockApplication sharedInstance] lock];
@weakify(self);
controller.onAuthenticationBlock = ^(A0UserProfile *profile, A0Token *token) {
NSLog(@"SUCCESS %@", profile);
Expand All @@ -134,6 +126,7 @@ - (void)loginTouchID:(id)sender {
- (void)loginSMS:(id)sender {
[self.keychain clearAll];
A0SMSLockViewController *controller = [[A0SMSLockViewController alloc] init];
controller.lock = [[A0LockApplication sharedInstance] lock];
controller.closable = YES;
@weakify(self);
controller.auth0APIToken = ^{
Expand Down
33 changes: 33 additions & 0 deletions Lock/Lock/A0LockApplication.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// A0LockApplication.h
//
// Copyright (c) 2015 Auth0 (http://auth0.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#import <Foundation/Foundation.h>

@class A0Lock;

@interface A0LockApplication : NSObject

@property (readonly, nonatomic) A0Lock *lock;

+ (A0LockApplication *)sharedInstance;

@end
58 changes: 58 additions & 0 deletions Lock/Lock/A0LockApplication.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// A0LockApplication.m
//
// Copyright (c) 2015 Auth0 (http://auth0.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#import "A0LockApplication.h"

#import <Lock/Lock.h>

@implementation A0LockApplication

- (instancetype)init {
self = [super init];
if (self) {
_lock = [A0Lock new];
A0TwitterAuthenticator *twitter = [A0TwitterAuthenticator newAuthenticatorWithKey:@""
andSecret:@""];
twitter.clientProvider = _lock;
A0FacebookAuthenticator *facebook = [A0FacebookAuthenticator newAuthenticatorWithDefaultPermissions];
facebook.clientProvider = _lock;
NSString *googlePlusClientId = [[NSBundle mainBundle] infoDictionary][@"GooglePlusClientId"];
A0GooglePlusAuthenticator *googleplus = [A0GooglePlusAuthenticator newAuthenticatorWithClientId:googlePlusClientId];
googleplus.clientProvider = _lock;
[[A0IdentityProviderAuthenticator sharedInstance] registerAuthenticationProviders:@[
twitter,
facebook,
googleplus,
]];
}
return self;
}

+ (A0LockApplication *)sharedInstance {
static A0LockApplication *instance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[A0LockApplication alloc] init];
});
return instance;
}
@end
4 changes: 3 additions & 1 deletion Lock/Lock/A0ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#import <SimpleKeychain/A0SimpleKeychain.h>
#import <JWTDecode/A0JWTDecoder.h>
#import <ReactiveCocoa/ReactiveCocoa.h>
#import "A0LockApplication.h"

@interface A0ViewController ()

Expand All @@ -46,7 +47,8 @@ - (void)viewDidLoad {
RACCommand *refreshCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
@strongify(self);
NSString* refreshToken = [self.keychain stringForKey: @"refresh_token"];
return [[A0APIClient sharedClient] fetchNewIdTokenWithRefreshToken:refreshToken parameters:nil];
A0APIClient *client = [[[A0LockApplication sharedInstance] lock] apiClient];
return [client fetchNewIdTokenWithRefreshToken:refreshToken parameters:nil];
}];
[[refreshCommand.executionSignals flatten] subscribeNext:^(A0Token *token) {
@strongify(self);
Expand Down
17 changes: 13 additions & 4 deletions Lock/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '8.0'

def pod_with_warnings
pod 'libextobjc', :inhibit_warnings => true #Ignore warnings for this lib
pod 'BDBOAuth1Manager', :inhibit_warnings => true #Ignore warnings for this lib
pod 'Facebook-iOS-SDK', :inhibit_warnings => true #Ignore warnings for this lib
pod 'ISO8601DateFormatter', :inhibit_warnings => true #Ignore warnings for this lib
end

target 'Lock', :exclusive => true do
pod 'Lock', :path => '../'
pod 'Lock/TouchID', :path => '../'
pod 'Lock/SMS', :path => '../'
pod 'Lock/ReactiveCore', :path => '../'
pod 'Lock/GooglePlus', :path => '../'
pod 'Lock/1Password', :path => '../'
pod 'libextobjc', :inhibit_warnings => true #Ignore warnings for this lib
pod 'BDBOAuth1Manager', :inhibit_warnings => true #Ignore warnings for this lib

pod_with_warnings

pod 'JWTDecode'
pod 'SimpleKeychain'
end
Expand All @@ -19,11 +27,12 @@ target 'Tests', :exclusive => true do
pod 'Lock', :path => '../'
pod 'Lock/TouchID', :path => '../'
pod 'Lock/SMS', :path => '../'
pod 'libextobjc', :inhibit_warnings => true #Ignore warnings for this lib
pod 'BDBOAuth1Manager', :inhibit_warnings => true #Ignore warnings for this lib

pod_with_warnings

pod 'Specta', '~> 0.5'
pod 'Expecta'
pod 'OCMockito'
pod 'OHHTTPStubs'
pod 'OCHamcrest', :inhibit_warnings => true #Ignore warnings for this lib
end
5 changes: 4 additions & 1 deletion Lock/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ PODS:
DEPENDENCIES:
- BDBOAuth1Manager
- Expecta
- Facebook-iOS-SDK
- ISO8601DateFormatter
- JWTDecode
- libextobjc
- Lock (from `../`)
Expand All @@ -168,6 +170,7 @@ DEPENDENCIES:
- Lock/ReactiveCore (from `../`)
- Lock/SMS (from `../`)
- Lock/TouchID (from `../`)
- OCHamcrest
- OCMockito
- OHHTTPStubs
- SimpleKeychain
Expand Down Expand Up @@ -203,4 +206,4 @@ SPEC CHECKSUMS:
TouchIDAuth: f63596baf1c23d85211ab7a3b4bea794d73f3e36
TWReverseAuth: d2deef3521fa6bee32eabab67f114c2c4a53d4f5

COCOAPODS: 0.37.0
COCOAPODS: 0.37.1
Loading