I have a website running on ASP.NET MVC 4.5.2. I have an IdentityServer4 server running but when I try and authenticate against it I get an:
invalid_request
For ASP.NET Core MVC the documentation has:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
AuthenticationScheme = "oidc",
SignInScheme = "Cookies",
Authority = "http://localhost:5000",
RequireHttpsMetadata = false,
ClientId = "mvc",
SaveTokens = true
});
I am including the following NuGet package in my project Microsoft.Owin.Security.OpenIdConnect. My code is as follows:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
AuthenticationType = "oidc",
SignInAsAuthenticationType = "Cookies",
Authority = "http://localhost:5000",
ClientId = "mvc",
});
How would one correctly connect to it?
The current version (IdentityServer4 v4. x) will be the last version we work on as free open source. We will keep supporting IdentityServer4 until the end of life of . NET Core 3.1 in November 2022.
the allowed interactions with the token service (called a grant type) a network location where identity and/or access token gets sent to (called a redirect URI)
IdentityServer is an authentication server that implements OpenID Connect (OIDC) and OAuth 2.0 standards for ASP.NET Core. It's designed to provide a common way to authenticate requests to all of your applications, whether they're web, native, mobile, or API endpoints.
OK I got this working.
You need to add the following NuGet package to your solution Microsoft.Owin.Security.OpenIdConnect .
My Startup.Auth.cs
contains
public void ConfigureAuth(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
Authority = "http://localhost:5000", //ID Server
ClientId = "demo",
ResponseType = "id_token code",
SignInAsAuthenticationType = "Cookies",
RedirectUri = "http://localhost:51048/signin-oidc", //URL of website
Scope = "openid",
});
}
My Client config in IdentityServer is:
public static IEnumerable<Client> GetClients()
{
return new List<Client> {
new Client {
ClientId = "demo",
AllowedScopes = new List<string> { "openid"},
AllowedGrantTypes = GrantTypes.Hybrid,
RedirectUris = new List<string>{"http://localhost:51048/signin-oidc"},
}
};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With