labyrinth
labyrinth

Reputation: 1164

JWTSecurityTokenHandler and SecurityTokenDescriptor not found even though System.IdentityModel.Tokens installed and used

I am trying to write a method to generate JWT token in .net C#. Searching through internet I found pages demonstrating how do do this. One such page I am following is https://gist.github.com/pmhsfelix/4151369. To support this, I ran "Install-Package System.IdentityModel.Tokens.Jwt" in the package manager console and can see "<package id="System.IdentityModel.Tokens.Jwt" version="4.0.2.205111437" targetFramework="net45" />" in my paackages.config. But still, the SecurityTokenDescriptor is not found. I have a strong feeling it is some version mismatch but I am not able to find out what is it. Can some one help me fix this?

Upvotes: 12

Views: 20165

Answers (2)

Ujimot0
Ujimot0

Reputation: 51

After upgrading from 4.x.x to 5.x.x

Change this line:

using System.IdentityModel.Tokens;

To:

using System.IdentityModel.Tokens.Jwt;

Upvotes: 5

Prisecaru Alin
Prisecaru Alin

Reputation: 251

Make sure that in your code you use:

using System.IdentityModel.Tokens;
using Microsoft.IdentityModel;

Also, I believe you will need to add a reference to:

System.IdentityModel

which is found in the Assemblies tab in Visual Studio.

Hope this helps you.

Upvotes: 11

Related Questions