Skip to content

Commit

Permalink
Support custom oauth2 strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaxson committed Aug 27, 2015
1 parent af5c46e commit 3071ab2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
13 changes: 13 additions & 0 deletions Pod/Assets/UI/Services.plist
Original file line number Diff line number Diff line change
Expand Up @@ -405,5 +405,18 @@
<key>selected_background_color</key>
<string>9B6014</string>
</dict>
<key>dropbox</key>
<dict>
<key>title</key>
<string>dropbox</string>
<key>foreground_color</key>
<string>ffffff</string>
<key>icon_character</key>
<string>d</string>
<key>background_color</key>
<string>7b8994</string>
<key>selected_background_color</key>
<string>47525d</string>
</dict>
</dict>
</plist>
2 changes: 2 additions & 0 deletions Pod/Classes/UI/A0LockConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

- (NSArray *)socialStrategies;

- (NSArray *)socialConnections;

- (NSArray *)enterpriseStrategies;

- (A0Strategy *)activeDirectoryStrategy;
Expand Down
10 changes: 10 additions & 0 deletions Pod/Classes/UI/A0LockConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
13 changes: 7 additions & 6 deletions Pod/Classes/UI/Private/A0SocialLoginViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand Down

0 comments on commit 3071ab2

Please sign in to comment.