Use OWIN Ws-Federation package to authenticate against ADFS 3.0

后端 未结 3 1529
梦如初夏
梦如初夏 2021-02-02 16:03

I have an MVC intranet site that needs to use AD accounts for authentication.

I setup ADFS 3.0 (Win Server 2012 R2) and followed this to setup the ADFS Relying Party Tr

3条回答
  •  春和景丽
    2021-02-02 16:30

    Actually, you are just missing this line that is usually before the UseCookieAuthentication method call.

    app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
    

    in your case it would be

    app.UseExternalSignInCookie(WsFederationAuthenticationDefaults.AuthenticationType);
    

    This is what actually gets executed when you call UseExternalSignInCookie(...), externalAuthenticationType is what you pass in as the string parameter.

    app.SetDefaultSignInAsAuthenticationType(externalAuthenticationType);
    CookieAuthenticationOptions options = new CookieAuthenticationOptions();
    options.AuthenticationType = externalAuthenticationType;
    options.AuthenticationMode = AuthenticationMode.Passive;
    options.CookieName = ".AspNet." + externalAuthenticationType;
    options.ExpireTimeSpan = TimeSpan.FromMinutes(5.0);
    app.UseCookieAuthentication(options);
    

    So, if all you are setting is the AuthenticationType, you can safely just call UseExternalSignInCookie as it does it for you.

提交回复
热议问题