Click here to Skip to main content
15,883,990 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've tried to implement JWT/OAuth With Identity 2.1 in single Application MVC 5 in better words OAuth server and the resource server are the same, Since i am new to the concept i am doing as this Tutorial has done so. At the moment I am stuck with Getting signingCredentials going.

In Code below, When i Reference it as System.IdentityModel.Token i can't use it in JwtSecurityToken. When i Reference it as Microsoft.IdentityModel.Token the SigningCredentials only takes only 2 parameters, but i have to define 3 as shown in tutorial. Would you please recommend a way to solve this issue? thank you in advance.

What I have tried:

public string Protect(AuthenticationTicket data)
{
if (data == null) throw new ArgumentNullException("data");

var issuer = "localhost";
var audience = "all";
var key = Convert.FromBase64String("UHxNtYMRYwvfpO1dS5pWLKL0M2DgOj40EbN4SoBWgfc");
var now = DateTime.UtcNow.AddHours(3.5);
var expires = now.AddMinutes(_options.AccessTokenExpireTimeSpan.TotalMinutes);

var signingCredentials = new System.IdentityModel.Tokens.SigningCredentials(
new InMemorySymmetricSecurityKey(key),
SignatureAlgorithm,
DigestAlgorithm);

var token = new JwtSecurityToken(issuer, audience, data.Identity.Claims,
now, expires, signingCredentials);

return new JwtSecurityTokenHandler().WriteToken(token);
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900