Created
December 11, 2018 07:32
-
-
Save ahelland/ba6cd4d22d40be5ebd01bbad4aa5c7fe to your computer and use it in GitHub Desktop.
Returning claims from a token after authorization
This file contains hidden or 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
[HttpGet] | |
[Authorize(Policy = "Certificate")] | |
[Route("Validate")] | |
public ActionResult<IEnumerable<string>> Validate() | |
{ | |
var token = "{"; | |
foreach (var claim in User.Claims) | |
{ | |
//Datetimes are already escaped | |
if (claim.Type.ToString().Contains("time")) | |
{ | |
token += $"\"{claim.Type}\":{claim.Value},"; | |
} | |
else | |
{ | |
//Let's not care about the authentication method here | |
//since that requires an array for building valid json | |
if (claim.Type == ClaimTypes.AuthenticationMethod) | |
{ } | |
else | |
{ | |
token += $"\"{claim.Type}\":\"{claim.Value}\","; | |
} | |
} | |
} | |
//Remove the surplus comma | |
token = token.Substring(0, token.Length - 1); | |
token += "}"; | |
return Content(token, "application/json"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment