IdentityServer 4

Startup Class for MVC application

using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Microsoft.Owin.Extensions;
using Owin;
using System.IdentityModel.Tokens;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.OpenIdConnect;
using System.Linq;
using System.Security.Claims;
using IdentityModel.Client;
using Microsoft.IdentityModel.Protocols;
using Microsoft.Owin.Security;
using System.IdentityModel.Tokens.Jwt;

[assembly: OwinStartup(typeof(SSO.App_Start.Startup))]
namespace SSO.App_Start
    public class Startup
        public void ConfigureServices(IAppBuilder app)
            app.UseCookieAuthentication(new CookieAuthenticationOptions
                AuthenticationType = "Cookies"
            app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
                AuthenticationType = "oidc",
                SignInAsAuthenticationType = "Cookies",
                Authority = "http://localhost:5000", //ID Server SSO Server
                ClientId = "mvc.hybrid",
                ClientSecret = "secret",
                ResponseType = "code id_token",
                RedirectUri = "http://localhost:55471/signin-oidc", //URL of Client website
                PostLogoutRedirectUri = "http://localhost:55471/signout-callback-oidc", //URL of Client website
                Scope = "openid",
                AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active,
                RequireHttpsMetadata = false,


        public void Configuration(IAppBuilder app)


If You want user information to take your claims list modify client code like below

For MVC Application Install Following package. otherwise startup class not hit

Install-Package Microsoft.Owin.Host.SystemWeb

From Nuget following Packages have to import for startup class

Microsoft.Owin.Security  -
Microsoft.Owin; -
Microsoft.Owin.Security.Cookies -
Microsoft.Owin.Security.OpenIdConnect  -

Web config set following property

No comments:

Post a Comment