@@ -164,6 +164,20 @@ void DisplayUserInfo(Firebase.Auth.IUserInfo userInfo, int indentLevel) {
164
164
}
165
165
}
166
166
167
+ // Display a more detailed view of a FirebaseUser.
168
+ void DisplayDetailedUserInfo ( Firebase . Auth . FirebaseUser user , int indentLevel ) {
169
+ DisplayUserInfo ( user , indentLevel ) ;
170
+ DebugLog ( " Anonymous: " + user . IsAnonymous ) ;
171
+ DebugLog ( " Email Verified: " + user . IsEmailVerified ) ;
172
+ var providerDataList = new List < Firebase . Auth . IUserInfo > ( user . ProviderData ) ;
173
+ if ( providerDataList . Count > 0 ) {
174
+ DebugLog ( " Provider Data:" ) ;
175
+ foreach ( var providerData in user . ProviderData ) {
176
+ DisplayUserInfo ( providerData , indentLevel + 1 ) ;
177
+ }
178
+ }
179
+ }
180
+
167
181
// Track state changes of the auth object.
168
182
void AuthStateChanged ( object sender , System . EventArgs eventArgs ) {
169
183
Firebase . Auth . FirebaseAuth senderAuth = sender as Firebase . Auth . FirebaseAuth ;
@@ -179,16 +193,7 @@ void AuthStateChanged(object sender, System.EventArgs eventArgs) {
179
193
if ( signedIn ) {
180
194
DebugLog ( "Signed in " + user . UserId ) ;
181
195
displayName = user . DisplayName ?? "" ;
182
- DisplayUserInfo ( user , 1 ) ;
183
- DebugLog ( " Anonymous: " + user . IsAnonymous ) ;
184
- DebugLog ( " Email Verified: " + user . IsEmailVerified ) ;
185
- var providerDataList = new List < Firebase . Auth . IUserInfo > ( user . ProviderData ) ;
186
- if ( providerDataList . Count > 0 ) {
187
- DebugLog ( " Provider Data:" ) ;
188
- foreach ( var providerData in user . ProviderData ) {
189
- DisplayUserInfo ( providerData , 2 ) ;
190
- }
191
- }
196
+ DisplayDetailedUserInfo ( user , 1 ) ;
192
197
}
193
198
}
194
199
}
@@ -260,7 +265,7 @@ public void UpdateUserProfile(string newDisplayName = null) {
260
265
void HandleUpdateUserProfile ( Task authTask ) {
261
266
EnableUI ( ) ;
262
267
if ( LogTaskCompletion ( authTask , "User profile" ) ) {
263
- DisplayUserInfo ( auth . CurrentUser , 1 ) ;
268
+ DisplayDetailedUserInfo ( auth . CurrentUser , 1 ) ;
264
269
}
265
270
}
266
271
@@ -293,6 +298,22 @@ void HandleSigninResult(Task<Firebase.Auth.FirebaseUser> authTask) {
293
298
LogTaskCompletion ( authTask , "Sign-in" ) ;
294
299
}
295
300
301
+ void LinkWithCredential ( ) {
302
+ if ( auth . CurrentUser == null ) {
303
+ DebugLog ( "Not signed in, unable to link credential to user." ) ;
304
+ return ;
305
+ }
306
+ DebugLog ( "Attempting to link credential to user..." ) ;
307
+ Firebase . Auth . Credential cred = Firebase . Auth . EmailAuthProvider . GetCredential ( email , password ) ;
308
+ auth . CurrentUser . LinkWithCredentialAsync ( cred ) . ContinueWith ( HandleLinkCredential ) ;
309
+ }
310
+
311
+ void HandleLinkCredential ( Task authTask ) {
312
+ if ( LogTaskCompletion ( authTask , "Link Credential" ) ) {
313
+ DisplayDetailedUserInfo ( auth . CurrentUser , 1 ) ;
314
+ }
315
+ }
316
+
296
317
public void ReloadUser ( ) {
297
318
if ( auth . CurrentUser == null ) {
298
319
DebugLog ( "Not signed in, unable to reload user." ) ;
@@ -304,7 +325,7 @@ public void ReloadUser() {
304
325
305
326
void HandleReloadUser ( Task authTask ) {
306
327
if ( LogTaskCompletion ( authTask , "Reload" ) ) {
307
- DisplayUserInfo ( auth . CurrentUser , 1 ) ;
328
+ DisplayDetailedUserInfo ( auth . CurrentUser , 1 ) ;
308
329
}
309
330
}
310
331
@@ -325,6 +346,15 @@ void HandleGetUserToken(Task<string> authTask) {
325
346
}
326
347
}
327
348
349
+ void GetUserInfo ( ) {
350
+ if ( auth . CurrentUser == null ) {
351
+ DebugLog ( "Not signed in, unable to get info." ) ;
352
+ } else {
353
+ DebugLog ( "Current user info:" ) ;
354
+ DisplayDetailedUserInfo ( auth . CurrentUser , 1 ) ;
355
+ }
356
+ }
357
+
328
358
public void SignOut ( ) {
329
359
DebugLog ( "Signing out." ) ;
330
360
auth . SignOut ( ) ;
@@ -347,7 +377,7 @@ void HandleDeleteResult(Task authTask) {
347
377
}
348
378
349
379
// Show the providers for the current email address.
350
- public void DisplayProviders ( ) {
380
+ public void DisplayProvidersForEmail ( ) {
351
381
auth . FetchProvidersForEmailAsync ( email ) . ContinueWith ( ( authTask ) => {
352
382
if ( LogTaskCompletion ( authTask , "Fetch Providers" ) ) {
353
383
DebugLog ( String . Format ( "Email Providers for '{0}':" , email ) ) ;
@@ -469,20 +499,26 @@ void GUIDisplayControls(){
469
499
if ( GUILayout . Button ( "Sign In With Credentials" ) ) {
470
500
SigninWithCredential ( ) ;
471
501
}
502
+ if ( GUILayout . Button ( "Link With Credential" ) ) {
503
+ LinkWithCredential ( ) ;
504
+ }
472
505
if ( GUILayout . Button ( "Reload User" ) ) {
473
506
ReloadUser ( ) ;
474
507
}
475
508
if ( GUILayout . Button ( "Get User Token" ) ) {
476
509
GetUserToken ( ) ;
477
510
}
511
+ if ( GUILayout . Button ( "Get User Info" ) ) {
512
+ GetUserInfo ( ) ;
513
+ }
478
514
if ( GUILayout . Button ( "Sign Out" ) ) {
479
515
SignOut ( ) ;
480
516
}
481
517
if ( GUILayout . Button ( "Delete User" ) ) {
482
518
DeleteUser ( ) ;
483
519
}
484
- if ( GUILayout . Button ( "Show Providers" ) ) {
485
- DisplayProviders ( ) ;
520
+ if ( GUILayout . Button ( "Show Providers For Email " ) ) {
521
+ DisplayProvidersForEmail ( ) ;
486
522
}
487
523
if ( GUILayout . Button ( "Password Reset Email" ) ) {
488
524
SendPasswordResetEmail ( ) ;
0 commit comments