0

我正在为我的网站使用asp.net样板。我有aspnetboilerplate/module-zero(OWIN)的标准认证。从Windows Phone 8.1的ASP.NET锅板验证 - 不记名令牌

但现在我需要为我的Windows Phone应用程序(wp8.1) 我试图配置我与承载授权的应用程序,但我失败了athentication .. 如何configurate asp.net样板申请我的Windows Phone应用程序权威性?

在Windows Phone的应用程序我发帖子到我的网页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

可以是它会帮助你 [ASP .NET身份和移动客户端] :http://stackoverflow.com/questions/22126305/asp-net-identity-and-mobile-clients –

回答

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