This repository was archived by the owner on Aug 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathSADProviderListViewController.m
More file actions
102 lines (76 loc) · 2.65 KB
/
SADProviderListViewController.m
File metadata and controls
102 lines (76 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// SADProviderListViewController.m
// SimpleAuth
//
// Created by Caleb Davenport on 1/16/14.
// Copyright (c) 2014 Byliner, Inc. All rights reserved.
//
#import "SADProviderListViewController.h"
#import "SimpleAuth.h"
@interface SADProviderListViewController ()
@end
@implementation SADProviderListViewController
#pragma mark - NSObject
- (instancetype)init {
if ((self = [super initWithStyle:UITableViewStylePlain])) {
self.title = @"SimpleAuth";
}
return self;
}
#pragma mark - UIViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
self.tableView.rowHeight = 50.0;
self.tableView.separatorInset = UIEdgeInsetsZero;
}
#pragma mark - Private
+ (NSArray *)providers {
static dispatch_once_t token;
static NSArray *array;
dispatch_once(&token, ^{
array = @[
@"twitter",
@"twitter-web",
@"facebook",
@"facebook-web",
@"instagram",
@"meetup",
@"tumblr",
@"foursquare-web",
@"dropbox-web",
@"linkedin-web",
@"facebook-sso"
];
});
return array;
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[[self class] providers] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.textLabel.text = [[self class] providers][indexPath.row];
return cell;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSString *provider = [[self class] providers][indexPath.row];
NSDictionary *configuration = SimpleAuth.configuration[provider];
if ([configuration count] == 0 && ![provider isEqualToString:@"facebook-sso"]) {
NSLog(@"It looks like you haven't configured the \"%@\" provider.\n"
"Consider calling +[SimpleAuth configuration] in `application:willFinishLaunchingWithOptions: "
"and providing all relevant options for the given provider.",
provider);
return;
}
[SimpleAuth authorize:provider completion:^(id responseObject, NSError *error) {
NSLog(@"\nResponse: %@\nError:%@", responseObject, error);
}];
}
@end