【问题标题】:User is not getting authenticated (cookies not getting set) after SAML getting processed successfully成功处理 SAML 后,用户未通过身份验证(未设置 cookie)
【发布时间】:2018-12-28 20:55:21
【问题描述】:

我正在使用 idp 发起的 SSO 流。我正在通过 OWIN 中间件使用 Kentor.AuthServices。

除了在成功处理 SAML 响应后控件到达我的回调方法时,用户身份没有得到SET之外,大部分流程都可以工作。

在 web.config 中设置:

<kentor.authServices entityId="https://one-staging.com/MVSAMLServiceProvider" 
                     returnUrl="https://5814a15e.ngrok.io/api/Account/UnsolicitedExternalLogin">
    <identityProviders>
      <add entityId="https://shibidp.edu/idp/shibboleth"
          metadataLocation = "~/Providers/SAML2/Metadata/shibidp.edu.xml"
          allowUnsolicitedAuthnResponse="false" 
          disableOutboundLogoutRequests="false"
          binding="HttpRedirect">
      </add>
      <add entityId="abb:one:saml20:idp"
           metadataLocation="~/Providers/SAML2/Metadata/abb.xml"
           allowUnsolicitedAuthnResponse="true"
           disableOutboundLogoutRequests="false"
           binding="HttpRedirect">
      </add>
    </identityProviders>
</kentor.authServices>

这是我的 Startup.cs:

public void ConfigureOAuth(IAppBuilder app)
{
    app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie);

    OAuthBearerOptions = new OAuthBearerAuthenticationOptions();
    OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
    {
        //For Dev enviroment only (on production should be AllowInsecureHttp = false)
        AllowInsecureHttp = true,
        TokenEndpointPath = new PathString("/oauth2/token"),
        AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30),
        Provider = new CustomOAuthProvider(),
        AccessTokenFormat = new CustomJwtFormat()
    };

    // OAuth 2.0 Bearer Access Token Generation
    app.UseOAuthAuthorizationServer(OAuthServerOptions);
    app.UseOAuthBearerAuthentication(OAuthBearerOptions);

    googleAuthOptions = new GoogleOAuth2AuthenticationOptions()
    {
        ClientId = System.Configuration.ConfigurationManager.AppSettings["GoogleClientId"],
        ClientSecret = System.Configuration.ConfigurationManager.AppSettings["GoogleClientSecret"],
        Provider = new GoogleAuthProvider()
    };
    app.UseGoogleAuthentication(googleAuthOptions);


    app.Use(async (Context, next) =>{await next.Invoke();});    
    app.UseKentorAuthServicesAuthentication(CreateSAMLAuthServicesOptions());
    app.Use(async (Context, next) =>{await next.Invoke();});
}

这里是 Kentor 日志(日志中没有错误):

DEBUG 2018-12-28 14:02:32,682  8859ms emv-authService-logger MoveNext           - Received unsolicited Saml Response _t0r6DHtsGygxkYcfNzdkEs72.M which is allowed for idp abb:one:saml20:idp
DEBUG 2018-12-28 14:02:32,729  8906ms emv-authService-logger MoveNext           - Signature validation passed for Saml Response _t0r6DHtsGygxkYcfNzdkEs72.M
DEBUG 2018-12-28 14:02:32,729  8906ms emv-authService-logger MoveNext           - Extracted SAML assertion oN4v.k9x2GE7s5S8OdeNWS.93j9
DEBUG 2018-12-28 14:02:32,729  8906ms emv-authService-logger MoveNext           - Validated conditions for SAML2 Response _t0r6DHtsGygxkYcfNzdkEs72.M
INFO  2018-12-28 14:02:32,729  8906ms emv-authService-logger ProcessResponse    - Successfully processed SAML response _t0r6DHtsGygxkYcfNzdkEs72.M and authenticated 10035094

最后我的重定向方法:

[OverrideAuthentication]
[HostAuthentication(DefaultAuthenticationTypes.ApplicationCookie)]
[AllowAnonymous]
[Route("UnsolicitedExternalLogin", Name = "UnsolicitedExternalLogin")]
public async void GetUnsolicitedExternalLogin()
{
    bool isAuthenticated = User.Identity.IsAuthenticated; //getting false
}

不幸的是,我已经被这个问题困扰了一个星期了。我相信这真的很接近完成,所以任何帮助将不胜感激。

谢谢!

【问题讨论】:

  • GetUnsolicitedExternalLogin 中,User.Identity 对象是什么样的。 IsAuthenticated 属性并不总是可靠的,它背后的逻辑有点奇特。
  • 这就是它的样子:User object

标签: saml-2.0 kentor-authservices sustainsys-saml2


【解决方案1】:

看代码,我认为认证方案不匹配。

在管道设置中,设置了用于外部身份验证方案的 cookie 中间件。但是在GetUnsolicitedExternalLogin 方法中,引用了ApplicationCookie 方案。将其更改为引用外部方案。

检查从~/AuthServices/AcsGetUnsolicitedExternalLogin 的重定向是否设置了外部身份验证cookie 也是一个好主意。

【讨论】:

  • 是的!这就是问题所在。将其更改为 DefaultAuthenticationTypes.ExternalCookie 使其工作。非常感谢!!!!!!!
  • 如果这解决了您的问题,请将答案标记为已接受(如果您想给我一些额外的分数,也可以投票)。不需要写感谢评论:)
猜你喜欢
  • 2019-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-16
  • 1970-01-01
  • 1970-01-01
  • 2018-03-30
  • 2018-11-15
相关资源
最近更新 更多