Created
September 6, 2019 15:31
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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