PolarisLib (1.9.0)
Installation
dotnet nuget add source --name neto --username your_username --password your_token https://gitea.jbsn.com.br/api/packages/neto/nuget/index.jsondotnet add package --source neto --version 1.9.0 PolarisLibAbout this package
No description
English | Portuguese
Polaris
What is it?
PolarisLib is a lightweight client library and helper NuGet package that complements the Polaris API (https://github.com/NetoBatista/polaris_api). It provides reusable services, integrations and extension methods to simplify adding authentication and authorization to ASP.NET projects. Install the package to register authentication services, optional generated controllers, token utilities and provider integrations (Firebase, Google OAuth2) so your application can authenticate users against a Polaris backend.
How does it work?
PolarisLib exposes an extension method AddPolarisAuthorization(IConfiguration) that registers the library's services into the application's dependency injection container. Behavior is controlled by configuration under the Polaris section in appsettings.json (for example: Key, GenerateController, PrefixRouter, and provider-specific settings).
When enabled, the library can dynamically generate controller routes (controlled by GenerateController) under the configured prefix (PrefixRouter) and wire up:
- Authentication services (e.g.
PolarisAuthenticationService) and handlers for request flows - An integration client (
PolarisIntegration) to call the Polaris API - Token utilities (
TokenUtil) for creating and validating JWTs - Adapters for external providers (Firebase, Google OAuth2) and helper request/response models
Typical usage:
- Add the NuGet package to your project.
- Call
builder.Services.AddPolarisAuthorization(builder.Configuration)inProgram.cs. - Configure the required options in
appsettings.json(at minimum thePolaris:Key).
At runtime the library registers the services and (optionally) controller endpoints that your application uses to authenticate users, generate/refresh tokens, and integrate with the Polaris authentication API and external providers.
Getting Started
Generate package using the command:
dotnet pack --configuration Release --output .
push the package using the command:
dotnet nuget push "PolarisLib.1.9.0.nupkg" --source "gitea"
create in your project the file nuget.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="gitea" value="https://gitea.jbsn.com.br/api/packages/neto/nuget/index.json" />
</packageSources>
<packageSourceCredentials>
<gitea>
<add key="Username" value="neto" />
<add key="ClearTextPassword" value="1891eea97d10b1ae3f038578205c856affdcc2d0" />
</gitea>
</packageSourceCredentials>
</configuration>
after this, execute the command:
dotnet add package PolarisLib
How to use ?
In the file program.cs add the code:
builder.Services.AddPolarisAuthorization(builder.Configuration);
To configure authentication, put the options in appSettings.json
Minimum configuration required
"Polaris": {
"Key": "a6c9fe83-dcde-4495-98cc-e218a22924a2"
}
Complete configuration
"Polaris": {
"Key": "a6c9fe83-dcde-4495-98cc-e218a22924a2",
"GenerateController": true,
"PrefixRouter": "api",
"Authentication": {
"OnGenerateCode": {
"CreateUserAutomatic": false
},
"GoogleOAuth2": {
"ClientId": "a8b7857a-492e-45da-adad-43ac65acbec1"
},
"Firebase" : {
"AppId": "da1c3f06-0e5f-44c6-a38a-5ec6b02a0094",
"JsonCredencials": "f7dfa792-815c-4bf8-aae5-db0f2cdebfcc"
}
},
"User": {
"OnCreate": {
"Roles": [
"ROLE1",
"ROLE2"
]
}
}
}