Keycloak.WAPI.Security
1.0.0
dotnet add package Keycloak.WAPI.Security --version 1.0.0
NuGet\Install-Package Keycloak.WAPI.Security -Version 1.0.0
<PackageReference Include="Keycloak.WAPI.Security" Version="1.0.0" />
<PackageVersion Include="Keycloak.WAPI.Security" Version="1.0.0" />
<PackageReference Include="Keycloak.WAPI.Security" />
paket add Keycloak.WAPI.Security --version 1.0.0
#r "nuget: Keycloak.WAPI.Security, 1.0.0"
#:package Keycloak.WAPI.Security@1.0.0
#addin nuget:?package=Keycloak.WAPI.Security&version=1.0.0
#tool nuget:?package=Keycloak.WAPI.Security&version=1.0.0
Keycloak .NET web API bearer token implementation.
Implementation steps,
Create a Startup class to initialize the keycloak configurations, public class Startup { const string persistentAuthType = "KeycloakAuthentication";
public void Configuration(IAppBuilder app) { app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = persistentAuthType }); // You may also use this method if you have multiple authentication methods below, // or if you just like it better: app.SetDefaultSignInAsAuthenticationType(persistentAuthType); app.UseKeycloakAuthentication(new KeycloakAuthenticationOptions { KeycloakUrl = "Keycloak server Url", Realm = "Realm name", ClientId = "XXXXX", ClientSecret = "XXXXXXXXXXXXXXXXX", VirtualDirectory = "True", EnableWebApiMode = true, AuthenticationType = persistentAuthType, SignInAsAuthenticationType = "True", EnableBearerTokenAuth = true, //ForceBearerTokenAuth = true, //Token validation options - these are all set to defaults AllowUnsignedTokens = false, DisableIssuerSigningKeyValidation = false, DisableIssuerValidation = false, DisableAudienceValidation = true }); }}
Add the below line of code to the .Net Web API controller class to load the startup class when there is a call to the .Net Web API service. This line of code should be in the namespace reference section. [assembly: OwinStartup(typeof(Startup))]
Add "[Authorize]" attribute either at the API controller level or at the API action level to secure it via keycloak.
Please note that you need to pass the keycloak authentication token as a HTTP header to the calling Web API service . The authorization token would be get on valid login by the user. Also, remember to set the HTTP header for the token as "Authorization" header to read by the Keycloak.WAPI.Security otherwise fails.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 811 | 8/9/2019 |