Rocket.Libraries.Auth
1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Rocket.Libraries.Auth --version 1.0.0
NuGet\Install-Package Rocket.Libraries.Auth -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rocket.Libraries.Auth" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rocket.Libraries.Auth --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Rocket.Libraries.Auth, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Rocket.Libraries.Auth as a Cake Addin #addin nuget:?package=Rocket.Libraries.Auth&version=1.0.0 // Install Rocket.Libraries.Auth as a Cake Tool #tool nuget:?package=Rocket.Libraries.Auth&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Rocket.Libraries.Auth
An bare-bones dotnet wrapper around the excellent JWT library, to simplify encoding and decoding of tokens.
Quick Start
1. Installation
Install the package from nuget
2. Configure your dotnet app
- Include in your startup.cs file.
using Rocket.Libraries.Auth;
- Implement the IRocketJwtSecretProvider interface.
public class LatticeSecretProvider : IRocketJwtSecretProvider`
{
/// <summary>
/// All this method requires to do is return a string to be used as the secret
/// during encoding and decoding.
/// </summary>
/// <returns></returns>
public Task<string> GetSecretAsync()
{
return Task.FromResult("something extremely secret");
}
}
- Register services auth library in your ConfigureServices method.
public void ConfigureServices (IServiceCollection services)
{
services.SetupRocketJwtAuth<LatticeSecretProvider>();
//Register other services
}
3. Encoding and Decoding Tokens
After installation and configuration as detailed above, you can now encode and decode tokens as show in the example class below.
public class TokenManager
{
private readonly IRocketJwtIssuer rocketJwtIssuer;
private readonly IRocketJwtTokenDecoder rocketJwtTokenDecoder;
private readonly IMySystemAuthenticator mySystemAuthenticator;
public TokenManager(
IRocketJwtIssuer rocketJwtIssuer, //Provided Rocket.Library.Auth works out of box
IRocketJwtTokenDecoder rocketJwtTokenDecoder, //Provided Rocket.Library.Auth works out of box
IMySystemAuthenticator mySystemAuthenticator)
{
this.rocketJwtIssuer = rocketJwtIssuer;
this.rocketJwtTokenDecoder = rocketJwtTokenDecoder;
this.mySystemAuthenticator = mySystemAuthenticator;
}
public async Task GetClaimsAsync(string token)
{
// Below call returns claims dictionary
// Also verifies signature.
var claims = await rocketJwtTokenDecoder.DecodeTokenAsync(token);
}
public async Task<string> GetTokenAsync()
{
// Sign into your system and return an object of type
// Rocket.Libraries.Auth.NativeAuthenticationResult
var nativeAuthenticationResult = await mySystemAuthenticator.SignInAsync();
//Flag whether authentication succeeded or not.
nativeAuthenticationResult.Authenticated = true;
// Add your claims (IDictionary<string,object>)
nativeAuthenticationResult.Claims.Add("role", "admin");
nativeAuthenticationResult.Claims.Add("userId", 23);
// Set the lifetime of the token in seconds
nativeAuthenticationResult.LifetimeSeconds = 3600;
// Call the token issuer
return await rocketJwtIssuer.GetTokenAsync(nativeAuthenticationResult);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 3.1
- JWT (>= 8.4.2)
- Microsoft.Extensions.Configuration (>= 3.1.18)
- Microsoft.Extensions.Options (>= 3.1.18)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 3.1.18)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Rocket.Libraries.Auth:
Package | Downloads |
---|---|
Jattac.Users.Management.Sdk
Wrapper to simplify authentication with Jattac.User.Management service |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.2 | 296 | 6/15/2023 |
1.0.1 | 171 | 6/14/2023 |
1.0.0 | 473 | 10/11/2021 |
1.0.0-beta02 | 334 | 10/10/2021 |
1.0.0-beta01 | 224 | 10/8/2021 |