首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >来自Windows phone8.1的ASP.NET样板身份验证-持有者令牌

来自Windows phone8.1的ASP.NET样板身份验证-持有者令牌
EN

Stack Overflow用户
提问于 2015-08-09 20:55:39
回答 1查看 759关注 0票数 0

我在我的网站上使用了asp.net样板。在那里我有来自aspnetboilerplate/module-zero(OWIN)的标准身份验证。

但是现在我需要对我的windows phone应用程序(wp8.1)进行身份验证,我正在尝试将我的应用程序配置为使用持有者授权,但失败了。如何为windows phone应用程序身份验证配置asp.net样板应用程序?

在windows phone应用程序中,我将post发送到我的web api,如下所示:

代码语言:javascript
代码运行次数:0
运行
复制
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

EN

回答 1

Stack Overflow用户

发布于 2015-12-23 17:33:42

现在已经在模块0模板中记录和实现了这一点

代码:在模块WebApi中:

代码语言:javascript
代码运行次数:0
运行
复制
Configuration.Modules.AbpWebApi().HttpConfiguration.Filters.Add(new HostAuthenticationFilter("Bearer"));

在控制器WebApi中:

代码语言:javascript
代码运行次数:0
运行
复制
[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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31904448

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档