API Key Authorization Module for ABP Based Applications
This module provides adding and managing dynamic API Keys with permissions for your application.
The API Key Authorization Management UI is currently available for only MVC applications.
The API Key Authorization is currently available for only Entity Framework.
An application programming interface key (API key) is a unique identifier used to authenticate a user, developer, or calling program to an API. However, they are typically used to authenticate a project with the API rather than a human user. Different platforms may implement and use API keys in different ways. (ref: wikipedia)
- API Keys Module uses distrubuted cache for responding faster.
This module's projects are not published yet as NuGet packages, so for now, you need to download the module via GitHub and add references each project to related application project.
-
Download the module source code
-
Add project references one by one as following:
*.Domain.Shared
->Cotur.Abp.ApiKeyAuthorization.Domain.Shared
*.Domain
->Cotur.Abp.ApiKeyAuthorization.Domain
-
Add module types as
DependsOn
attribute parameter.- Example for Domain module:
[DependsOn( //.. typeof(ApiKeyAuthorizationDomainModule) )]
-
Add configuration for your
*.HttpApi.Host
or*.Web
project.public async override Task OnApplicationInitializationAsync(ApplicationInitializationContext context) { var app = context.GetApplicationBuilder(); var env = context.GetEnvironment(); // .. app.UseAuthentication(); app.UseApiKeyAuthorization(); app.UseAuthorization(); //.. }
-
Configure your
DbContext
protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); //.. modelBuilder.ConfigureApiKeyAuthorization(); }
-
Add migrations & update your database
-
[Optional] Set your api key name at your module class.
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<ApiKeyOptions>(o =>
{
o.ApiKeyName = "my-key-name";
});
}
or
appsettings.json
{
"apiKeys": {
"apiKeyName": "my-key-name"
}
}