我在我的网站上使用了asp.net样板。在那里我有来自aspnetboilerplate/module-zero(OWIN)的标准身份验证。
但是现在我需要对我的windows phone应用程序(wp8.1)进行身份验证,我正在尝试将我的应用程序配置为使用持有者授权,但失败了。如何为windows phone应用程序身份验证配置asp.net样板应用程序?
在windows phone应用程序中,我将post发送到我的web api,如下所示:
public static async Task<TokenResponseModel> GetBearerToken(string siteUrl, string Username, string Password)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(siteUrl);
client.DefaultRequestHeaders.Accept.Clear();
HttpContent requestContent = new StringContent("grant_type=password&username=" + Username + "&password=" + Password, Encoding.UTF8, "application/x-www-form-urlencoded");
HttpResponseMessage responseMessage = await client.PostAsync("Token", requestContent);
if (responseMessage.IsSuccessStatusCode)
{
string jsonMessage;
using (Stream responseStream = await responseMessage.Content.ReadAsStreamAsync())
{
jsonMessage = new StreamReader(responseStream).ReadToEnd();
}
TokenResponseModel tokenResponse = (TokenResponseModel)JsonConvert.DeserializeObject(jsonMessage, typeof(TokenResponseModel));
return tokenResponse;
}
else
{
return null;
}
}
但是我应该在WebApi中做什么呢?auth和next响应载体以及在下一步中如何使用载体在类上使用AbpAuthorize时如何使用auth
发布于 2015-12-23 17:33:42
现在已经在模块0模板中记录和实现了这一点
代码:在模块WebApi中:
Configuration.Modules.AbpWebApi().HttpConfiguration.Filters.Add(new HostAuthenticationFilter("Bearer"));
在控制器WebApi中:
[HttpPost]
public async Task<AjaxResponse> Authenticate(LoginModel loginModel)
{
CheckModelState();
var loginResult = await GetLoginResultAsync(
loginModel.UsernameOrEmailAddress,
loginModel.Password,
loginModel.TenancyName
);
var ticket = new AuthenticationTicket(loginResult.Identity, new AuthenticationProperties());
var currentUtc = new SystemClock().UtcNow;
ticket.Properties.IssuedUtc = currentUtc;
ticket.Properties.ExpiresUtc = currentUtc.Add(TimeSpan.FromMinutes(30));
return new AjaxResponse(OAuthBearerOptions.AccessTokenFormat.Protect(ticket));
}
文档:http://aspnetboilerplate.com/Pages/Documents/Zero/Startup-Template#token-based-authentication
https://stackoverflow.com/questions/31904448
复制相似问题