ASP.NET Basic Usage - dylanplecki/KeycloakOwinAuthentication GitHub Wiki
Basic usage of this project includes calling the UseKeycloakAuthentication
extension method from within the web application's OWIN startup class.
The following is a brief example on how to do so using the Microsoft.Owin.Host.SystemWeb
and Microsoft.Owin.Security.Cookies
packages:
// File: Startup.cs
using Microsoft.Owin;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Cookies;
using Owin;
using Owin.Security.Keycloak;
[assembly: OwinStartup(typeof (Sample.KeycloakAuth.Startup))]
namespace Sample.KeycloakAuth
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
const string persistentAuthType = "keycloak_cookies"; // Or name it whatever you want
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
{
Realm = "master",
ClientId = "sample_keycloakAuth",
ClientSecret = "3a06aae9-53d2-43a9-ba00-f188ff7b6d99",
KeycloakUrl = "http://keycloak.site.com/auth",
SignInAsAuthenticationType = persistentAuthType // Not required with SetDefaultSignInAsAuthenticationType
});
}
}
}