0

I need to run some logic in an ASP.NET API action using the claims in the passed in access token. How do I get the access token? And later how do I get the claim value in the access token?

[HttpGet]
[Authorize(Policy = "PaidMember")]
[Route("GetVideos")]
public async Task<IEnumerable<VideoModel>> GetVideos(string topicId)
{
    var accessToken = ... // TODO: Get the access token here

    // Then something like the following
    var type = accessToken.GetValue("membershiptype") // This line is made up
    return await _service.GetVideos(topicId, type );
}
1
  • 1
    this link can be useful to you Commented Dec 18, 2020 at 9:34

3 Answers 3

2

You can get the claims with :

HttpContext.User.Claims

See here for get a specific claim : Extract values from HttpContext.User.Claims

I suggest you to use the ASP pipeline with Authorization middlware if you want to check claims. See Microsoft Docs - ASP.NET Core Middleware.

Sign up to request clarification or add additional context in comments.

Comments

1

You can get the claim value like this:

(User.Identity as ClaimsIdentity).FindFirst("membershiptype").Value

With this you do not need to get the original token

Comments

0

you can go through the following link as a reference for your queries https://www.youtube.com/watch?v=B2jDN53taDk&list=PL6n9fhu94yhW7yoUOGNOfHurUE6bpOO2b&index=23

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.