• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 *
3 * Copyright 2015 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19#import "SelectUserViewController.h"
20
21#import "MakeRPCViewController.h"
22
23@implementation SelectUserViewController
24
25- (void)viewDidLoad {
26  [super viewDidLoad];
27
28  self.signOutButton.layer.cornerRadius = 5;
29  self.signOutButton.hidden = YES;
30
31  // As instructed in https://developers.google.com/identity/sign-in/ios/sign-in
32  GIDSignIn *signIn = GIDSignIn.sharedInstance;
33  signIn.delegate = self;
34  signIn.uiDelegate = self;
35
36  // As instructed in https://developers.google.com/identity/sign-in/ios/additional-scopes
37  if (![signIn.scopes containsObject:kTestScope]) {
38    signIn.scopes = [signIn.scopes arrayByAddingObject:kTestScope];
39  }
40
41  [signIn signInSilently];
42}
43
44- (void)signIn:(GIDSignIn *)signIn
45didSignInForUser:(GIDGoogleUser *)user
46     withError:(NSError *)error {
47  if (error) {
48    // The user probably cancelled the sign-in flow.
49    return;
50  }
51
52  self.mainLabel.text = [NSString stringWithFormat:@"User: %@", user.profile.email];
53  NSString *scopes = [user.accessibleScopes componentsJoinedByString:@", "];
54  scopes = scopes.length ? scopes : @"(none)";
55  self.subLabel.text = [NSString stringWithFormat:@"Scopes: %@", scopes];
56
57  self.signInButton.hidden = YES;
58  self.signOutButton.hidden = NO;
59}
60
61- (IBAction)didTapSignOut {
62  [GIDSignIn.sharedInstance signOut];
63
64  self.mainLabel.text = @"Please sign in.";
65  self.subLabel.text = @"";
66
67  self.signInButton.hidden = NO;
68  self.signOutButton.hidden = YES;
69}
70
71@end
72