【发布时间】:2016-08-07 01:53:18
【问题描述】:
我有带有自定义登录实现的 mvc5 应用程序。一旦我从用户那里获得凭据,就会发布并获取令牌以验证用户。 在单独的类库项目中实现 Owin Token。
[HttpPost]
[AllowAnonymous]
public ActionResult Login(UserLoginViewModel model)
{
string baseAddress = "http://localhost:4312";
Token token = new Token();
using (var client = new HttpClient())
{
var form = new Dictionary<string, string>
{
{"grant_type", "password"},
{"username", "jignesh"},
{"password", "user123456"},
};
var tokenResponse = client.PostAsync(baseAddress + "/otoken", new FormUrlEncodedContent(form)).Result;
//var token = tokenResponse.Content.ReadAsStringAsync().Result;
token = tokenResponse.Content.ReadAsAsync<Token>(new[] { new JsonMediaTypeFormatter() }).Result;
........
}
}
我不确定如何从 mvc 应用程序调用/触发类库项目中的令牌实现。因为类库项目不是可执行项目。是否有可能在单独的类库中实现基于令牌的实现,并在不同的应用程序(mvc 和 webapi)中使用该实现。
我的图层
UI(MVC) -> 认证项目(Owin 类库) -> 实体框架
有什么想法吗?
【问题讨论】:
标签: c# asp.net-mvc asp.net-web-api owin asp.net-mvc-5