blob: 954c531f3fba771e9ce9941d80986d1f054829a0 [file] [log] [blame]
Jorge Canizales4da10122015-06-11 12:02:30 -07001/*
2 *
3 * Copyright 2015, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34#import "SelectUserViewController.h"
35
Jorge Canizales64428ac2015-06-11 15:21:55 -070036#import "MakeRPCViewController.h"
Jorge Canizales36009772015-06-11 13:10:38 -070037
Jorge Canizales4da10122015-06-11 12:02:30 -070038@implementation SelectUserViewController
39
40- (void)viewDidLoad {
41 [super viewDidLoad];
42
43 self.signOutButton.layer.cornerRadius = 5;
44 self.signOutButton.hidden = YES;
45
46 // As instructed in https://developers.google.com/identity/sign-in/ios/sign-in
Jorge Canizales36009772015-06-11 13:10:38 -070047 GIDSignIn *signIn = GIDSignIn.sharedInstance;
48 signIn.delegate = self;
49 signIn.uiDelegate = self;
Jorge Canizales4da10122015-06-11 12:02:30 -070050
Jorge Canizales36009772015-06-11 13:10:38 -070051 // As instructed in https://developers.google.com/identity/sign-in/ios/additional-scopes
52 if (![signIn.scopes containsObject:kTestScope]) {
53 signIn.scopes = [signIn.scopes arrayByAddingObject:kTestScope];
54 }
55
56 [signIn signInSilently];
Jorge Canizales4da10122015-06-11 12:02:30 -070057}
58
59- (void)signIn:(GIDSignIn *)signIn
60didSignInForUser:(GIDGoogleUser *)user
61 withError:(NSError *)error {
62 if (error) {
63 // The user probably cancelled the sign-in flow.
64 return;
65 }
66
67 self.mainLabel.text = [NSString stringWithFormat:@"User: %@", user.profile.email];
68 NSString *scopes = [user.accessibleScopes componentsJoinedByString:@", "];
69 scopes = scopes.length ? scopes : @"(none)";
70 self.subLabel.text = [NSString stringWithFormat:@"Scopes: %@", scopes];
71
72 self.signInButton.hidden = YES;
73 self.signOutButton.hidden = NO;
74}
75
76- (IBAction)didTapSignOut {
77 [GIDSignIn.sharedInstance signOut];
Jorge Canizales36009772015-06-11 13:10:38 -070078
Jorge Canizales4da10122015-06-11 12:02:30 -070079 self.mainLabel.text = @"Please sign in.";
80 self.subLabel.text = @"";
Jorge Canizales36009772015-06-11 13:10:38 -070081
Jorge Canizales4da10122015-06-11 12:02:30 -070082 self.signInButton.hidden = NO;
83 self.signOutButton.hidden = YES;
84}
85
86@end