Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SymmetricSecurityKey in ASP.NET CORE

Tags:

asp.net

jwt

I'm trying to create Asp.NET Core API and add Jwt authentication. In all examples, that I've found so far is used SymmetricSecurityKey. I've added Aspnetcore.Authentication.JwtBearer package but there is doesn't exist SymmetricSecurityKey. What package I've to add to resolve dependency to this class?

Thank you in advance.

like image 204
Timur Yaroshenko Avatar asked May 12 '17 16:05

Timur Yaroshenko


People also ask

What is the use of Symmetricsecuritykey?

Determines whether the specified object is equal to the current object. When overridden in a derived class, generates a derived key using the specified cryptographic algorithm and parameters for the current key.

What is JWT token in .NET core?

JSON Web Tokens (commonly known as JWT) is an open standard to pass data between client and server, and enables you to transmit data back and forth between the server and the consumers in a secure manner. This article talks about how you can take advantage of JWTs to protect APIs.

How do I authenticate in .NET core?

Additional resources. Authentication is the process of determining a user's identity. Authorization is the process of determining whether a user has access to a resource. In ASP.NET Core, authentication is handled by the authentication service, IAuthenticationService, which is used by authentication middleware.


2 Answers

For .NET Core 3.0:

A lot of things have been broken off into individual packages that have to be added to your project. Therefore:

$ dotnet add package Microsoft.AspNetCore.Authentication.JwtBearer --version 3.0.0

Which adds the following line to the .csproj:

<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.0.0" />

At that point, as other answers have stated, you can import:

using System.IdentityModel.Tokens.Jwt;

Nuget Package Link

like image 167
Kurtis Jungersen Avatar answered Oct 23 '22 12:10

Kurtis Jungersen


For me it required using Microsoft.IdentityModel.Tokens;

like image 23
AlwaysLearning Avatar answered Oct 23 '22 10:10

AlwaysLearning