Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin Azure移动服务身份验证-使用sql表更改令牌存储?_Xamarin_Azure Mobile Services - Fatal编程技术网

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

Xamarin Azure移动服务身份验证-使用sql表更改令牌存储?,xamarin,azure-mobile-services,Xamarin,Azure Mobile Services,根据有关文件,据说 Azure应用程序服务身份验证/授权维护令牌 存储在XDrive中(这是所有用户共享的驱动器 同一应用程序服务计划中的后端实例)。代币 存储位于后端的D:\home\data\.auth\tokens。这个 令牌被加密并存储在每个用户的加密文件中 我猜XDrive是blob存储。我有自己的asp.net成员资格用户表,它已经使用MVC和web api为google、facebook、amazon等实现了外部登录。 我想知道我是否可以更改令牌存储,并使用这些表来保证我的web和

根据有关文件,据说

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

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

我已经使用web api为我现有的登录实现了用户名/密码登录,它运行良好。因此,如果我也可以使用azure移动服务,而不是azure active directory

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

我假设你想用。如果是这种情况,您可以实现自定义端点以接受用户参数,并在数据库中检查用户名和密码。以下是来自

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