【问题标题】:How to get X-Zumo-auth token in Azure Mobile service如何在 Azure 移动服务中获取 X-Zumo-auth 令牌
【发布时间】:2017-01-15 00:18:17
【问题描述】:

我计划在我的应用中自动化一些场景。基本上 5 个不同的用户在使用移动客户端应用程序时调用了一些 api。现在为了模拟这一点,我需要用 X-ZUMO-Auth 调用我的服务器 api,只是想知道如何为 5 个不同的测试用户提供 X-Zumo-auth。我尝试调用 https:///.auth/login/facebook/ 然后 https:///.auth/me 这给了我 Facebook 的誓言令牌。

【问题讨论】:

    标签: azure azure-mobile-services


    【解决方案1】:

    使用以下函数创建一个 24 小时有效的令牌。

    您需要有您的 SigningKey(如果它是较新的 AppServices 移动设备,您可以使用 Environment.GetEnvironmentVariable("WEBSITE_AUTH_SIGNING_KEY") 代替。

        public static string CreateToken(string userid)
        {
            JwtSecurityToken token = AppServiceLoginHandler.CreateToken(new Claim[] { new Claim(JwtRegisteredClaimNames.Sub, userid) },
                 ConfigurationManager.AppSettings["SigningKey"],
                 ConfigurationManager.AppSettings["ValidAudience"],
                 ConfigurationManager.AppSettings["ValidIssuer"],
                 TimeSpan.FromHours(24));
            return token.RawData;
        }
    

    【讨论】:

      猜你喜欢
      • 2016-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-08
      • 2017-12-07
      • 1970-01-01
      • 1970-01-01
      • 2015-08-18
      相关资源
      最近更新 更多