OWIN 登录不工作
OWIN Signin not working
User.Identity.IsAuthenticated 始终为假。我已经用谷歌搜索了几个小时,但无法正常工作。我有一组声明,我正在使用 OWIN 创建身份并使用它登录,但出于某种原因,IsAuthenticated 始终为 false。
这是我的 web.config 相关部分:
<authentication mode="Forms">
<forms name="FormsAuth1" loginUrl="https://localhost/SecureAuth.ClaimsAdapter.WebApp/Oidc/Authenticate" timeout="5" requireSSL="false" domain="localhost" />
</authentication>
这里是Startup.Auth.cs
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
LoginPath = new PathString("/OIDC/Authenticate")
});
这是我的控制器
var identity = new ClaimsIdentity(validatedToken.Claims, DefaultAuthenticationTypes.ExternalCookie);
//Sign in using the created identity
HttpContext.GetOwinContext().Authentication.SignIn(identity);
//redirect to Pass the cookie to the client app
return RedirectToAction("Confirm");
在"Confirm" 操作中,"User.Identity.IsAuthenticated" 仍然设置为false。
您必须将 CookieAuthenticationMiddleware.AuthenticationType
设置为与 DefaultSignInAsAuthenticationType
相同的类型。
这应该有效
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
//Change this to CookieAuthenticationDefaults.AuthenticationType
AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
LoginPath = new PathString("/OIDC/Authenticate")
});
//Change this to CookieAuthenticationDefaults.AuthenticationType
var identity = new ClaimsIdentity(validatedToken.Claims, CookieAuthenticationDefaults.AuthenticationType);
//Sign in using the created identity
HttpContext.GetOwinContext().Authentication.SignIn(identity);
//redirect to Pass the cookie to the client app
return RedirectToAction("Confirm");
显然,我没有打电话给
ConfigureAuth(IappBuilder 应用程序)....
继续打自己耳光...
User.Identity.IsAuthenticated 始终为假。我已经用谷歌搜索了几个小时,但无法正常工作。我有一组声明,我正在使用 OWIN 创建身份并使用它登录,但出于某种原因,IsAuthenticated 始终为 false。
这是我的 web.config 相关部分:
<authentication mode="Forms">
<forms name="FormsAuth1" loginUrl="https://localhost/SecureAuth.ClaimsAdapter.WebApp/Oidc/Authenticate" timeout="5" requireSSL="false" domain="localhost" />
</authentication>
这里是Startup.Auth.cs
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
LoginPath = new PathString("/OIDC/Authenticate")
});
这是我的控制器
var identity = new ClaimsIdentity(validatedToken.Claims, DefaultAuthenticationTypes.ExternalCookie);
//Sign in using the created identity
HttpContext.GetOwinContext().Authentication.SignIn(identity);
//redirect to Pass the cookie to the client app
return RedirectToAction("Confirm");
在"Confirm" 操作中,"User.Identity.IsAuthenticated" 仍然设置为false。
您必须将 CookieAuthenticationMiddleware.AuthenticationType
设置为与 DefaultSignInAsAuthenticationType
相同的类型。
这应该有效
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
//Change this to CookieAuthenticationDefaults.AuthenticationType
AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
LoginPath = new PathString("/OIDC/Authenticate")
});
//Change this to CookieAuthenticationDefaults.AuthenticationType
var identity = new ClaimsIdentity(validatedToken.Claims, CookieAuthenticationDefaults.AuthenticationType);
//Sign in using the created identity
HttpContext.GetOwinContext().Authentication.SignIn(identity);
//redirect to Pass the cookie to the client app
return RedirectToAction("Confirm");
显然,我没有打电话给
ConfigureAuth(IappBuilder 应用程序)....
继续打自己耳光...