我正在为我的网站使用asp.net样板文件。我有来自aspnetboilerplate / module-zero(OWIN)的标准认证。
但现在我需要为我的Windows手机应用程序验证(wp8.1) 我正在尝试使用bearer配置我的应用程序授权,但我失败了.. 如何为我的windows phone app auth配置asp.net样板应用程序?
在Windows手机应用程序中,我将帖子发送到我的网页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中做些什么?在课堂上我是如何使用[AbpAuthorize]的身份验证和下一个响应承载以及下一步如何使用承载的身份验证?
答案 0 :(得分:0)
现在记录并在模块零模板
中实现代码: 在模块WebApi中:
byte[] buffer = new byte[length];
int bytesRead = in.read(buffer);
if (bytesRead != length) {
; // handle incomplete file transfer
}
在控制器WebApi中:
Configuration.Modules.AbpWebApi().HttpConfiguration.Filters.Add(new HostAuthenticationFilter("Bearer"));
文档:http://aspnetboilerplate.com/Pages/Documents/Zero/Startup-Template#token-based-authentication