【发布时间】:2018-02-28 13:37:34
【问题描述】:
我们在我们的应用程序中使用 owin 身份验证。我们可以通过 ApplicationCookie 使用身份验证和身份验证。为此,我们使用访问令牌代码,它工作正常。
app.Use(async (context, next) =>
{
if (string.IsNullOrWhiteSpace(context.Request.Headers.Get("Authorization")))
{
if (context.Request.QueryString.HasValue)
{
var queryString = HttpUtility.ParseQueryString(context.Request.QueryString.Value);
string token = queryString.Get("access_token");
if (!string.IsNullOrWhiteSpace(token))
{
context.Request.Headers.Add("Authorization", new[] { string.Format("Bearer {0}", token) });
}
}
}
await next();
});
问题是我们想要的一些功能不需要登录和使用令牌,这是目的令牌,我们可以说重置密码令牌或某些特定目的令牌。
目前我们正在使用应用程序 cookie,您可以在此处查看代码
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
CookieHttpOnly = false,
CookieName = CookieNames.FiboAuthentication,
LoginPath = new PathString("/Account/Login"),
LogoutPath = new PathString("/Account/Logout"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) =>
{
var api = Startup.CreateDatabaseApi();
return user.GenerateUserIdentityAsync(manager, DefaultAuthenticationTypes.ApplicationCookie, api);
})
}
});
有任何方法可以使用目的令牌进行身份验证或创建身份,然后我们可以在授权中使用此身份,并且我们的身份验证流程相同。
请建议最好的方法。谢谢。
【问题讨论】:
-
恐怕你的问题有点不清楚,什么是目的令牌?
-
谢谢。目的令牌只不过是我们使用重置密码的令牌代码,我们创建了自定义令牌。
标签: asp.net-mvc authentication asp.net-web-api owin identity