This is a nuget package built in ASP.NET Core to help quickly setup authentication up and running on your Web api app and also secure microservices. It's built on jwtBearer library.
MicroServiceAuthenticator can be installed via the nuget UI (as MicroServiceAuthenticator), or via the nuget package manager console:
PM> Install-Package MicroServiceAuthenticator
PM> Install-Package Microsoft.AspNetCore.Authentication.JwtBearer -Version 3.1.2
{
"TokenAuthentication": {
"SecretKey": "secret-key",
"Issuer": "issuer-app",
"Audience": "audience-key",
"ExpirationTime":300
}
}
After updating the application settings, open the Startup.cs file. Startup class is the heart of ASP.NET Core application’s configuration. First we need to import the MicroServiceAuthenticator
namespace.
The most important type in this library is the just adding it to the services configure pipline. Which can be added as shown below:
public ConfigureServices(IServiceCollection services)
{
services.AddMicroServiceAuthenticator(new TokenProviderOptions
{
Issuer = configuration["TokenAuthentication:Issuer"],
Audience = configuration["TokenAuthentication:Audience"],
SecretKey = configuration["TokenAuthentication:SecretKey"],
ExpirationTime = configuration["TokenAuthentication:ExpirationTime"]
});
}
Place the [Authorize]
attribute on the controller you want to authenticate and use the identity service to get your token and set the token to the authorization of the api endpoint and boom you are authenticated successfully.
Feel free to send a PR.
This project follows the all-contributors specification. Contributions of any kind are welcome!
MIT