Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cosmos extensions for the server
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using IdentityServer4.Extensions;
using Microsoft.AspNetCore.Identity;
using BlazorCosmosWasm.Server.Models;
using Microsoft.Azure.Cosmos;
using Microsoft.Extensions.Configuration;
namespace BlazorCosmosWasm.Server.Controllers
{
public static class CosmosExtensions
{
public async static Task<string> GetEmailAsync(this ClaimsPrincipal user, UserManager<ApplicationUser> userManager)
{
if (user.IsAuthenticated())
{
var id = user.Claims.SingleOrDefault(
key => key.Type == ClaimTypes.NameIdentifier)?.Value;
var appUser = await userManager.FindByIdAsync(id);
return appUser?.Email;
}
return null;
}
public static CosmosClient CreateCosmosClientFromConfig(this IConfiguration config)
{
return new CosmosClient(config.GetValue<string>("CosmosConnection"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.