DocumentDB + Xamarin - 授权令牌无效

时间:2017-03-27 04:36:01

标签: azure xamarin.ios xamarin.android xamarin.forms azure-cosmosdb

我正在尝试解决使用Xamarin Forms + DocumentDB制作的应用中的关键错误。我正在使用Microsoft.Azure.DocumentDB.Core包来存储数据。 我们的Azure帐户托管在巴西南部(GMT-3),应用程序正常运行。但我们注意到在区域设置时间GMT-4的地区,应用程序崩溃,但上面有例外。

The authorization token is not valid at the current time. Please 
create another token and retry (token start time: Mon, 27 Mar 2017
00:07:41 GMT, token expiry time: Mon, 27 Mar 2017 00:22:41 GMT, 
current server time: Mon, 27 Mar 2017 01:08:24 GMT).
ActivityId: 81487924-68ee-4329-bb61-02f88ea7b6ec

如果我将设备延迟一小时以获得GMT-4,并运行该应用程序,我可以看到异常。

    //---------------------------------------------static Repository initialize
    DocumentClient client;
    const string collectionId = "user";
    Uri uri = UriFactory.CreateDocumentCollectionUri(Constants.DB_ID, collectionId);

    //---------------------------------------------static constructor
    UserDataService()
    {
        client = new DocumentClient(
                new Uri(Constants.DB_ACCOUNT_URL),
                        Constants.DB_ACCOUNT_KEY);
    }

    async public Task<User> GetUserByCPF(string cpf)
    {
        var fedOpt = new FeedOptions { MaxItemCount = -1 };
        var query = client.CreateDocumentQuery<User>(uri, fedOpt)
                          .Where(x => x.Id == _id)
                          .AsDocumentQuery();

        var lst = new List<User>();
        while (query.HasMoreResults)
        {
            lst.AddRange(await query.ExecuteNextAsync<User>());
        }

        return lst.FirstOrDefault();
    }

查询中出现异常.ExecuteNextAsync;

错误消息说创建另一个令牌,但我正在使用万能钥匙。有人知道如何为万能钥匙创建一个令牌或增加到期日期?

1 个答案:

答案 0 :(得分:1)

根据我的经验,字符串的日期部分是 UTC日期,以便通过SDK生成令牌。而且我无法用我身边的不同区域来重复这个问题。我得到异常的唯一方法就是本地设备系统不正确。

enter image description here

所以我认为该异常是由设备使用错误时间引起的。