@@ -326,6 +326,109 @@ public async Task GetUserByPhoneNumberEmpty()
326326 await Assert . ThrowsAsync < ArgumentException > ( ( ) => auth . GetUserByPhoneNumberAsync ( string . Empty ) ) ;
327327 }
328328
329+ [ Fact ]
330+ public async Task GetUserByProviderUid ( )
331+ {
332+ var handler = new MockMessageHandler ( )
333+ {
334+ Response = GetUserResponse ,
335+ } ;
336+ var auth = this . CreateFirebaseAuth ( handler ) ;
337+
338+ var userRecord = await auth . GetUserByProviderUidAsync ( "google.com" , "google_uid" ) ;
339+
340+ Assert . Equal ( "user1" , userRecord . Uid ) ;
341+ Assert . Null ( userRecord . DisplayName ) ;
342+ Assert . Null ( userRecord . Email ) ;
343+ Assert . Null ( userRecord . PhoneNumber ) ;
344+ Assert . Null ( userRecord . PhotoUrl ) ;
345+ Assert . Equal ( "firebase" , userRecord . ProviderId ) ;
346+ Assert . False ( userRecord . Disabled ) ;
347+ Assert . False ( userRecord . EmailVerified ) ;
348+ Assert . Equal ( UserRecord . UnixEpoch , userRecord . TokensValidAfterTimestamp ) ;
349+ Assert . Empty ( userRecord . CustomClaims ) ;
350+ Assert . Empty ( userRecord . ProviderData ) ;
351+ Assert . Null ( userRecord . UserMetaData . CreationTimestamp ) ;
352+ Assert . Null ( userRecord . UserMetaData . LastSignInTimestamp ) ;
353+
354+ var request = NewtonsoftJsonSerializer . Instance . Deserialize < Dictionary < string , object > > ( handler . LastRequestBody ) ;
355+ Assert . Equal ( new JArray ( "{providerId: google.com, rawId: google_uid}" ) , request [ "federatedUserId" ] ) ;
356+ this . AssertClientVersion ( handler . LastRequestHeaders ) ;
357+ }
358+
359+ [ Fact ]
360+ public async Task GetUserByProviderUidWithPhoneProvider ( )
361+ {
362+ var handler = new MockMessageHandler ( )
363+ {
364+ Response = GetUserResponse ,
365+ } ;
366+ var auth = this . CreateFirebaseAuth ( handler ) ;
367+
368+ var userRecord = await auth . GetUserByProviderUidAsync ( "phone" , "+1234567890" ) ;
369+
370+ Assert . Equal ( "user1" , userRecord . Uid ) ;
371+
372+ var request = NewtonsoftJsonSerializer . Instance . Deserialize < Dictionary < string , object > > ( handler . LastRequestBody ) ;
373+ Assert . Equal ( new JArray ( "+1234567890" ) , request [ "phoneNumber" ] ) ;
374+ Assert . False ( request . ContainsKey ( "federatedUserId" ) ) ;
375+ this . AssertClientVersion ( handler . LastRequestHeaders ) ;
376+ }
377+
378+ [ Fact ]
379+ public async Task GetUserByProviderUidWithEmailProvider ( )
380+ {
381+ var handler = new MockMessageHandler ( )
382+ {
383+ Response = GetUserResponse ,
384+ } ;
385+ var auth = this . CreateFirebaseAuth ( handler ) ;
386+
387+ var userRecord = await auth . GetUserByProviderUidAsync ( "email" , "user@example.com" ) ;
388+
389+ Assert . Equal ( "user1" , userRecord . Uid ) ;
390+
391+ var request = NewtonsoftJsonSerializer . Instance . Deserialize < Dictionary < string , object > > ( handler . LastRequestBody ) ;
392+ Assert . Equal ( new JArray ( "user@example.com" ) , request [ "email" ] ) ;
393+ Assert . False ( request . ContainsKey ( "federatedUserId" ) ) ;
394+ this . AssertClientVersion ( handler . LastRequestHeaders ) ;
395+ }
396+
397+ [ Fact ]
398+ public async Task GetUserByProviderUidUserNotFound ( )
399+ {
400+ var handler = new MockMessageHandler ( )
401+ {
402+ Response = @"{""users"": []}" ,
403+ } ;
404+ var auth = this . CreateFirebaseAuth ( handler ) ;
405+
406+ var exception = await Assert . ThrowsAsync < FirebaseAuthException > (
407+ async ( ) => await auth . GetUserByProviderUidAsync ( "google.com" , "google_uid" ) ) ;
408+
409+ Assert . Equal ( ErrorCode . NotFound , exception . ErrorCode ) ;
410+ Assert . Equal ( AuthErrorCode . UserNotFound , exception . AuthErrorCode ) ;
411+ Assert . Equal ( "Failed to get user with federated user ID: {providerId: google.com, rawId: google_uid}" , exception . Message ) ;
412+ Assert . NotNull ( exception . HttpResponse ) ;
413+ Assert . Null ( exception . InnerException ) ;
414+ }
415+
416+ [ Fact ]
417+ public async Task GetUserByProviderUidNull ( )
418+ {
419+ var auth = this . CreateFirebaseAuth ( new MockMessageHandler ( ) ) ;
420+ await Assert . ThrowsAsync < ArgumentException > ( ( ) => auth . GetUserByProviderUidAsync ( "google.com" , null ) ) ;
421+ await Assert . ThrowsAsync < ArgumentException > ( ( ) => auth . GetUserByProviderUidAsync ( null , "google_uid" ) ) ;
422+ }
423+
424+ [ Fact ]
425+ public async Task GetUserByProviderUidEmpty ( )
426+ {
427+ var auth = this . CreateFirebaseAuth ( new MockMessageHandler ( ) ) ;
428+ await Assert . ThrowsAsync < ArgumentException > ( ( ) => auth . GetUserByProviderUidAsync ( "google.com" , string . Empty ) ) ;
429+ await Assert . ThrowsAsync < ArgumentException > ( ( ) => auth . GetUserByProviderUidAsync ( string . Empty , "google_uid" ) ) ;
430+ }
431+
329432 [ Fact ]
330433 public async Task ListUsers ( )
331434 {
0 commit comments