0

根据此处有关本章的文档,据说

Azure 应用服务身份验证/授权在 XDrive(这是在同一应用服务计划内的所有后端实例之间共享的驱动器)中维护一个令牌存储。令牌存储位于后端的 D:\home\data\.auth\tokens。令牌被加密并存储在每个用户的加密文件中。

我猜 XDrive 是 blob 存储。我有自己的 asp.net 会员用户表,它已经使用 MVC 和 web api 实现了 google、facebook、amazon 等的外部登录。我想知道是否可以更改令牌存储并使用这些表来确保我的 Web 和移动应用程序之间的完整性,而不是使用 2 个单独的解决方案。

我已经使用 web api 为我现有的登录实现了用户名/密码登录,它工作正常。因此,如果我也可以为此使用 azure 移动服务而不是 Azure 活动目录。

在此处输入图像描述

4

1 回答 1

0

我想知道是否可以更改令牌存储并使用这些表来确保我的 Web 和移动应用程序之间的完整性,而不是使用 2 个单独的解决方案。

我假设您想使用Custom Authentication。如果是这种情况,您可以实现自定义端点以接受用户参数并使用您的数据库检查用户名和密码。以下是文章中的代码片段

[Route(".auth/login/custom")]
    public class CustomAuthController : ApiController
    {
        private MobileServiceContext db;
        private string signingKey, audience, issuer;

        public CustomAuthController()
        {
            db = new MobileServiceContext();
            signingKey = Environment.GetEnvironmentVariable("WEBSITE_AUTH_SIGNING_KEY");
            var website = Environment.GetEnvironmentVariable("WEBSITE_HOSTNAME");
            audience = $"https://{website}/";
            issuer = $"https://{website}/";
        }

        [HttpPost]
        public IHttpActionResult Post([FromBody] User body)
        {
            if (body == null || body.Username == null || body.Password == null ||
                body.Username.Length == 0 || body.Password.Length == 0)
            {
                return BadRequest(); ;
            }

            if (!IsValidUser(body))   //add your logic to verify the use
            {  

                return Unauthorized();
            }

            var claims = new Claim[]
            {
                new Claim(JwtRegisteredClaimNames.Sub, body.Username)
            };

            JwtSecurityToken token = AppServiceLoginHandler.CreateToken(
                claims, signingKey, audience, issuer, TimeSpan.FromDays(30));
            return Ok(new LoginResult()
            {
                AuthenticationToken = token.RawData,
                User = new LoginResultUser { UserId = body.Username }
            });
        }
于 2018-05-29T09:05:00.550 回答