Authentication / Authorization MVC 5 and Web API - Katana/Owin

后端 未结 2 1330
离开以前
离开以前 2021-02-02 03:33

I\'m having problems trying to decide on a route to take on a project I have.

I\'ve been reading up on OWIN specs and Katana implementation within .NET. The reason why I

2条回答
  •  忘掉有多难
    2021-02-02 03:56

    Cmedine, based on Brett's answer i configured my authentication and authorization. I show you the code as you requested some sample code.

    public partial class Startup
    {
        public void ConfigureAuth(IAppBuilder app)
        {
            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
    
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                SlidingExpiration = false,
                CookieName = "identity",
                //short time for testing only
                ExpireTimeSpan = TimeSpan.FromSeconds(120),
                Provider = new CookieAuthenticationProvider
                {
                    OnResponseSignIn = ctx =>
                    {
                        ctx.Identity = TransformClaims(ctx);
                    }
                }
            });
    
            app.UseWsFederationAuthentication(
                new WsFederationAuthenticationOptions
                {
                    MetadataAddress = "https://[[ADFS_Url]]/FederationMetadata/2007-06/federationmetadata.xml",
                    Wtrealm = "[[realm]]",
                    UseTokenLifetime = false
                }
            );
    
        }
    
        private ClaimsIdentity TransformClaims(CookieResponseSignInContext ctx)
        {
            return new IdentityCreator().CreateIdentity(ctx.Identity, [[ApplicationName]]);
        }
    }
    

    The IdentityCreator takes the ClaimsIdentity and an Application name and goes to a DB and gets the claims for that user in that application. Hope it helps!!

提交回复
热议问题