Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snippets for new Admin auth features #163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Snippets for new Admin auth features
  • Loading branch information
samtstern committed Apr 1, 2020
commit 7b201e6db914968a6aa490d31643aeae31fda5ba
43 changes: 43 additions & 0 deletions FirebaseAdmin/FirebaseAdmin.Snippets/FirebaseAuthSnippets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 85,15 @@ internal static async Task GetUserByPhoneNumberAsync(string phoneNumber)
// [END get_user_by_phone]
}

internal static async Task GetUserByProviderUidAsync()
{
// [START get_user_by_federated_id]
UserRecord userRecord = await FirebaseAuth.DefaultInstance.GetUserByProviderUidAsync("google.com", "google_uid1234");
// See the UserRecord reference doc for the contents of userRecord.
Console.WriteLine($"Successfully fetched user data: {userRecord.Uid}");
// [END get_user_by_federated_id]
}

internal static async Task CreateUserAsync()
{
// [START create_user]
Expand Down Expand Up @@ -139,6 148,40 @@ internal static async Task UpdateUserAsync(string uid)
// [END update_user]
}

internal static async Task UpdateUserFederatedAsync(string uid)
{
// [START update_user_link_federated]
// Link the user with a federated identity provider (like Google).
UserRecordArgs args = new UserRecordArgs()
{
Uid = uid,
ProviderToLink = new ProviderUserInfo()
{
ProviderId = "google.com",
Uid = "google_uid1234",
},
};
UserRecord userRecord = await FirebaseAuth.DefaultInstance.UpdateUserAsync(args);
// See the UserRecord reference doc for the contents of userRecord.
Console.WriteLine($"Successfully updated user: {userRecord.Uid}");
// [END update_user_link_federated]

// [START update_user_unlink_federated]
// Unlink the user from a federated identity provider (like Google).
UserRecordArgs args = new UserRecordArgs()
{
Uid = uid,
ProvidersToDelete = new List<string>()
{
"google.com",
},
};
UserRecord userRecord = await FirebaseAuth.DefaultInstance.UpdateUserAsync(args);
// See the UserRecord reference doc for the contents of userRecord.
Console.WriteLine($"Successfully updated user: {userRecord.Uid}");
// [END update_user_unlink_federated]
}

internal static async Task DeleteUserAsync(string uid)
{
// [START delete_user]
Expand Down