代码之家  ›  专栏  ›  技术社区  ›  Emil

azure移动服务身份验证-使用sql表更改令牌存储?

  •  0
  • Emil  · 技术社区  · 6 年前

    根据文件 this chapter here ,据说

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

    我猜xdrive是blob存储器。我有自己的asp.net会员用户表,它已经使用mvc和web api为google、facebook、amazon等实现了外部登录。 我想知道我是否可以改变令牌存储,并使用这些表在我的网络和移动应用程序之间的完整性,而不是有两个独立的解决方案。

    我已经使用web api实现了我现有登录名的用户名/密码登录,并且运行良好。所以如果我也可以使用azure移动服务来代替azure active directory。

    enter image description here

    1 回复  |  直到 6 年前
        1
  •  0
  •   Tom Sun    6 年前

    我想知道我是否可以改变令牌存储,并使用这些表在我的网络和移动应用程序之间的完整性,而不是有两个独立的解决方案。

    我想你想用 Custom Authentication 是的。如果是这种情况,则可以实现自定义端点以接受用户参数,并使用数据库检查用户名和密码。下面是 article

    [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 }
                });
            }