0

我已经按照本页https://github.com/Sustainsys/Saml2/blob/master/docs/OwinMiddleware.md中提到的说明实现了对 Okta 的 SAML 身份验证支持。

第一次有人单击 Okta 中打开我的应用程序的磁贴时,身份验证不起作用。具体来说,来自我的 ExternalLoginCallback 函数的 AuthenticationManager.GetExternalLoginInfoAsync() 调用返回 null。

当用户第二次单击磁贴时,一切都按预期工作。

我可以通过从浏览器中为我的 Web 应用程序清除所有 cookie,然后尝试从 Okta 登录来始终重现该问题。第一次它总是失败,第二次它工作。

到目前为止,我已将其缩小到 1 个 cookie:ASP.NET_SessionId。如果我删除此 cookie 并尝试登录它会失败。

我的 ExternalLoginCallback 方法看起来很标准:

// GET: /Account/ExternalLoginCallback
[AllowAnonymous]
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
    var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
    if (loginInfo == null)
    {
        return RedirectToAction("Login");
    }

    // Sign in the user with this external login provider if the user already has a login
    var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent: false);
    switch (result)
    {
        case SignInStatus.Success:
            return RedirectToLocal(returnUrl);
        case SignInStatus.LockedOut:
            return View("Lockout");
        case SignInStatus.RequiresVerification:
            return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false });
        case SignInStatus.Failure:
        default:
            // If the user does not have an account, then prompt the user to create an account
            ViewBag.ReturnUrl = returnUrl;
            ViewBag.LoginProvider = loginInfo.Login.LoginProvider;
            return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email });
    }
}

我在这里想念什么?

注意: 我尝试了使用 Kentor Auth Services 附带的 SampleOwinApplication 应用程序清除 cookie 的相同步骤。这个应用程序适用于所有情况(即使在清除 cookie 之后)

4

1 回答 1

1

回答我自己的问题:原来是https://coding.abel.nu/2014/11/catching-the-system-webowin-cookie-monster/中描述的 cookie 怪物问题

只需将以下代码添加到 Startup.Auth.cs 即可解决问题。

app.UseKentorOwinCookieSaver();
于 2018-02-15T00:57:00.520 回答