@@ -31,6 +31,8 @@ @interface FIRAuthViewController () <FIRAuthUIDelegate>
3131@property (weak , nonatomic ) IBOutlet UITableViewCell *cellEmail;
3232@property (weak , nonatomic ) IBOutlet UITableViewCell *cellUID;
3333@property (weak , nonatomic ) IBOutlet UIBarButtonItem *btnAuthorization;
34+ @property (weak , nonatomic ) IBOutlet UITableViewCell *cellAccessToken;
35+ @property (weak , nonatomic ) IBOutlet UITableViewCell *cellIdToken;
3436
3537@property (nonatomic ) FIRAuth *auth;
3638@property (nonatomic ) FIRAuthUI *authUI;
@@ -41,9 +43,14 @@ @interface FIRAuthViewController () <FIRAuthUIDelegate>
4143
4244@implementation FIRAuthViewController
4345
46+ #pragma mark - UIViewController methods
47+
4448- (void )viewDidLoad {
4549 [super viewDidLoad ];
4650
51+ self.tableView .rowHeight = UITableViewAutomaticDimension;
52+ self.tableView .estimatedRowHeight = 240 ;
53+
4754 self.auth = [FIRAuth auth ];
4855 self.authUI = [FIRAuthUI defaultAuthUI ];
4956 self.authUI .delegate = self;
@@ -74,6 +81,14 @@ -(void)viewDidDisappear:(BOOL)animated {
7481 [self .auth removeAuthStateDidChangeListener: self .authStateDidChangeHandle];
7582}
7683
84+ #pragma mark - UITableViewController methods
85+
86+ - (CGFloat)tableView : (UITableView *)tableView heightForRowAtIndexPath : (NSIndexPath *)indexPath {
87+ return UITableViewAutomaticDimension;
88+ }
89+
90+ #pragma mark - UI methods
91+
7792- (void )updateUI : (FIRAuth * _Nonnull) auth withUser : (FIRUser * _Nullable) user {
7893 if (user) {
7994 self.cellSignIn .textLabel .text = @" YES" ;
@@ -91,35 +106,30 @@ - (void)updateUI:(FIRAuth * _Nonnull) auth withUser:(FIRUser * _Nullable) user {
91106 self.btnAuthorization .title = @" Sign In" ;
92107 }
93108
109+ self.cellAccessToken .textLabel .text = [self getAllAccessTokens ];
110+ self.cellIdToken .textLabel .text = [self getAllIdTokens ];
111+
112+ [self .tableView reloadData ];
94113}
95114
96115- (IBAction )onAuthorization : (id )sender {
97116 if (!self.auth .currentUser ) {
98117 UIViewController *controller = [self .authUI authViewController ];
99118 [self presentViewController: controller animated: YES completion: nil ];
100119 } else {
101- NSError *error;
102- [self .auth signOut: &error];
103- if (error) {
104- NSLog (@" Sign out error: %@ " , error);
105- }
120+ [self signOut ];
106121 }
107122}
108123
109124#pragma mark - FIRAuthUIDelegate methods
110125
111126- (void )authUI : (FIRAuthUI *)authUI didSignInWithUser : (nullable FIRUser *)user error : (nullable NSError *)error {
112127 if (error) {
113- NSError *originalError = error.userInfo [NSUnderlyingErrorKey ];
114- UIAlertController *alert = [UIAlertController alertControllerWithTitle: @" Error"
115- message: originalError.localizedDescription
116- preferredStyle: UIAlertControllerStyleAlert];
117- UIAlertAction* closeButton = [UIAlertAction
118- actionWithTitle: @" Close"
119- style: UIAlertActionStyleDefault
120- handler: nil ];
121- [alert addAction: closeButton];
122- [self presentViewController: alert animated: YES completion: nil ];
128+ NSError *detailedError = error.userInfo [NSUnderlyingErrorKey ];
129+ if (!detailedError) {
130+ detailedError = error;
131+ }
132+ [self showAlert: detailedError.localizedDescription];
123133 }
124134}
125135
@@ -145,5 +155,50 @@ - (NSString *)readFacebookAppId {
145155 return facebookAppId;
146156}
147157
158+ - (NSString *)getAllAccessTokens {
159+ NSMutableString *result = [NSMutableString new ];
160+ for (id <FIRAuthProviderUI> provider in _authUI.providers ) {
161+ [result appendFormat: @" %@ : %@ \n " , provider.shortName, provider.accessToken];
162+ }
163+
164+ return result;
165+ }
166+
167+ - (NSString *)getAllIdTokens {
168+ NSMutableString *result = [NSMutableString new ];
169+ for (id <FIRAuthProviderUI> provider in _authUI.providers ) {
170+ [result appendFormat: @" %@ : %@ \n " , provider.shortName, provider.idToken];
171+ }
172+
173+ return result;
174+ }
175+
176+ - (void )signOut {
177+ // sign out from Firebase
178+ NSError *error;
179+ [self .auth signOut: &error];
180+ if (error) {
181+ [self showAlert: error.localizedDescription];
182+ }
183+
184+ // sign out from all providers (wipes provider tokens too)
185+ for (id <FIRAuthProviderUI> provider in _authUI.providers ) {
186+ [provider signOutWithAuth: self .auth];
187+ }
188+
189+ }
190+
191+ - (void )showAlert : (NSString *)message {
192+ UIAlertController *alert = [UIAlertController alertControllerWithTitle: @" Error"
193+ message: message
194+ preferredStyle: UIAlertControllerStyleAlert];
195+ UIAlertAction* closeButton = [UIAlertAction
196+ actionWithTitle: @" Close"
197+ style: UIAlertActionStyleDefault
198+ handler: nil ];
199+ [alert addAction: closeButton];
200+ [self presentViewController: alert animated: YES completion: nil ];
201+
202+ }
148203
149204@end
0 commit comments