Skip to content

Instantly share code, notes, and snippets.

@mikepfeiffer
Created September 6, 2019 15:31
Show Gist options
  • Save mikepfeiffer/5dced926e04d5620dca2dd70c08aed99 to your computer and use it in GitHub Desktop.
Save mikepfeiffer/5dced926e04d5620dca2dd70c08aed99 to your computer and use it in GitHub Desktop.
Query email address from claims after sign in - ASP.NET Core Razor Pages
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Security.Claims;
namespace CloudSkills.Pages
{
public class ProtectedPageModel : PageModel
{
public IEnumerable<Claim> Claims { get; set; }
public string EmailClaim { get; set; }
[Authorize]
public void OnGet()
{
this.Claims = User.Claims;
var email = User.Claims.Where(e => e.Type == "emails")
.Select(e => e.Value).SingleOrDefault();
this.EmailClaim = email;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment