【发布时间】:2016-10-10 10:19:07
【问题描述】:
在我的应用程序中,我使用 MVC 和 Web.API。
MVC 部分处理管理前端、为cshtml 页面提供服务、与后端通信、使用 cookie 进行常规身份验证等:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
Web.API 处理 iOS 和 Android 应用程序发出的 REST 请求。对于那个我想使用基于令牌的身份验证:
var oAuthServerOptions = new OAuthAuthorizationServerOptions
{
AllowInsecureHttp = true, //todo-err: change in prod
TokenEndpointPath = new PathString("/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
Provider = new SimpleAuthorizationServerProvider()
};
// Token Generation
app.UseOAuthAuthorizationServer(oAuthServerOptions);
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
我的问题是,我需要什么才能完成这项工作?常规和令牌身份验证。我需要为 API 控制器创建自定义 AuthorizeAttribute 吗?
感谢您的帮助:)
【问题讨论】:
标签: asp.net-mvc authentication asp.net-web-api oauth owin