Transforming Open Id Connect claims in ASP.Net Core

前端 未结 4 835
时光说笑
时光说笑 2020-12-30 05:58

I\'m writing an ASP.Net Core Web Application and using UseOpenIdConnectAuthentication to connect it to IdentityServer3. Emulating their ASP.Net MVC 5 sample I\'

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-30 06:30

    You can implement OnSigningIn event of SignInScheme. Here is an example:

            app.UseCookieAuthentication(new CookieAuthenticationOptions()
            {
                AuthenticationScheme = "OpenIdCookies",
                AutomaticAuthenticate = true,
                Events = new CookieAuthenticationEvents()
                {
                    OnSigningIn = async (context) =>
                    {
                        ClaimsIdentity identity = (ClaimsIdentity)context.Principal.Identity;
                        identity.Claims = identity.Claims.Where(...);
                    }
                }
            });
    
            var oidcOptions = new OpenIdConnectOptions
            {
                AuthenticationScheme = "oidc",
                SignInScheme = "OpenIdCookies"
            };
    
            //.. set other options
    
            app.UseOpenIdConnectAuthentication(oidcOptions); 
    

提交回复
热议问题