From 3071ab22cb95e95e9e9457c2f8345e78b329927c Mon Sep 17 00:00:00 2001 From: John Laxson Date: Wed, 26 Aug 2015 20:56:28 -0700 Subject: [PATCH] Support custom oauth2 strategies --- Pod/Assets/UI/Services.plist | 13 +++++++++++++ Pod/Classes/UI/A0LockConfiguration.h | 2 ++ Pod/Classes/UI/A0LockConfiguration.m | 10 ++++++++++ .../UI/Private/A0SocialLoginViewController.m | 13 +++++++------ 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Pod/Assets/UI/Services.plist b/Pod/Assets/UI/Services.plist index 1531b4e39..baf23bec7 100644 --- a/Pod/Assets/UI/Services.plist +++ b/Pod/Assets/UI/Services.plist @@ -405,5 +405,18 @@ selected_background_color 9B6014 + dropbox + + title + dropbox + foreground_color + ffffff + icon_character + d + background_color + 7b8994 + selected_background_color + 47525d + diff --git a/Pod/Classes/UI/A0LockConfiguration.h b/Pod/Classes/UI/A0LockConfiguration.h index d264482fa..29ff6650f 100644 --- a/Pod/Classes/UI/A0LockConfiguration.h +++ b/Pod/Classes/UI/A0LockConfiguration.h @@ -34,6 +34,8 @@ - (NSArray *)socialStrategies; +- (NSArray *)socialConnections; + - (NSArray *)enterpriseStrategies; - (A0Strategy *)activeDirectoryStrategy; diff --git a/Pod/Classes/UI/A0LockConfiguration.m b/Pod/Classes/UI/A0LockConfiguration.m index 0809200e9..2fa9d93de 100644 --- a/Pod/Classes/UI/A0LockConfiguration.m +++ b/Pod/Classes/UI/A0LockConfiguration.m @@ -76,6 +76,16 @@ - (NSArray *)socialStrategies { return self.social; } +- (NSArray *)socialConnections { + NSMutableArray *connections = [NSMutableArray array]; + for (A0Strategy *strategy in self.social) { + for (A0Connection *conn in strategy.connections) { + [connections addObject:conn]; + } + } + return connections; +} + - (NSArray *)enterpriseStrategies { return self.enterprise; } diff --git a/Pod/Classes/UI/Private/A0SocialLoginViewController.m b/Pod/Classes/UI/Private/A0SocialLoginViewController.m index 103bb2139..e5c8ed044 100644 --- a/Pod/Classes/UI/Private/A0SocialLoginViewController.m +++ b/Pod/Classes/UI/Private/A0SocialLoginViewController.m @@ -23,6 +23,7 @@ #import "A0SocialLoginViewController.h" #import "A0Application.h" #import "A0Strategy.h" +#import "A0Connection.h" #import "A0IdentityProviderAuthenticator.h" #import "UIButton+A0SolidButton.h" #import "A0ServiceTableViewCell.h" @@ -72,18 +73,18 @@ - (void)viewDidLoad { UINib *cellNib = [UINib nibWithNibName:@"A0ServiceTableViewCell" bundle:[NSBundle bundleForClass:self.class]]; [self.tableView registerNib:cellNib forCellReuseIdentifier:kCellIdentifier]; self.services = [[A0ServicesTheme alloc] init]; - self.activeServices = self.configuration.socialStrategies; + self.activeServices = self.configuration.socialConnections; self.selectedService = NSNotFound; } - (void)triggerAuth:(UIButton *)sender { @weakify(self); self.selectedService = sender.tag; - A0Strategy *strategy = self.activeServices[sender.tag]; + A0Connection *connection = self.activeServices[sender.tag]; A0APIClientAuthenticationSuccess successBlock = ^(A0UserProfile *profile, A0Token *token){ @strongify(self); - [self postLoginSuccessfulForConnection:strategy.connections.firstObject]; + [self postLoginSuccessfulForConnection:connection]; [self setInProgress:NO]; if (self.onLoginBlock) { self.onLoginBlock(profile, token); @@ -107,15 +108,15 @@ - (void)triggerAuth:(UIButton *)sender { A0ShowAlertErrorView(error.localizedDescription, error.localizedFailureReason); break; default: - A0ShowAlertErrorView(A0LocalizedString(@"There was an error logging in"), [A0Errors localizedStringForConnectionName:strategy.name loginError:error]); + A0ShowAlertErrorView(A0LocalizedString(@"There was an error logging in"), [A0Errors localizedStringForConnectionName:connection.name loginError:error]); break; } } }; [self setInProgress:YES]; A0IdentityProviderAuthenticator *authenticator = [self a0_identityAuthenticatorFromProvider:self.lock]; - A0LogVerbose(@"Authenticating with connection %@", strategy.name); - [authenticator authenticateWithConnectionName:strategy.name parameters:self.parameters success:successBlock failure:failureBlock]; + A0LogVerbose(@"Authenticating with connection %@", connection.name); + [authenticator authenticateWithConnectionName:connection.name parameters:self.parameters success:successBlock failure:failureBlock]; } - (CGRect)rectToKeepVisibleInView:(UIView *)view {