Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

nuget

jwt

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?

like image 830
labyrinth Avatar asked May 20 '15 19:05

labyrinth


2 Answers

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.

like image 194
Prisecaru Alin Avatar answered Nov 20 '22 13:11

Prisecaru Alin


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

Change this line:

using System.IdentityModel.Tokens;

To:

using System.IdentityModel.Tokens.Jwt;
like image 40
Ujimot0 Avatar answered Nov 20 '22 14:11

Ujimot0