1

I'm trying to resolve a critical bug in my app made with Xamarin Forms + DocumentDB. I'm using the package Microsoft.Azure.DocumentDB.Core to store data. Our Azure account is hosted in Brazil South (GMT-3), and the apps works normally. But we notice that in districts with the locale time GMT-4, the app crash with the exception above.

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

If I delayed my device one hour to get GMT-4, and run the app I can see the exception.

    //---------------------------------------------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();
    }

The exceptions rises in query.ExecuteNextAsync;

The error message says to create another token, but I'm using the Master Key. Someone know how create a token to Master Key or increase the expiration date?

4
  • according to my knowledge by default, the validity period of a resource token is 1 hour. though it can be overridden and increased up to 5 hours. Please refer to this url : learn.microsoft.com/en-us/rest/api/documentdb/permissions And this stackoverflow thread, stackoverflow.com/questions/41761552/… Commented Mar 27, 2017 at 11:24
  • Hi @SaadMehmood thanks for the help. I tried this approach creating a token for Master Key, but the app still crashing. Commented Mar 28, 2017 at 20:31
  • I am thinking along the same lines as Tom. Assuming the error occurs when you already have a Token, but then change the time. Unfortunately they haven't released the source yet, hence I can't dig down to see how they store the token. github.com/Azure/azure-documentdb-dotnet/tree/master/sdk Commented Mar 30, 2017 at 10:27
  • @AdamPedley. As I told to Tom, still is a mistery how this token is created! Maybe when MS publish the code at github, we can answer this question. Again, thanks for the help. Best regards Commented Mar 30, 2017 at 16:44

1 Answer 1

1

Base on my experience, the date portion of the string is the UTC date to generate token by SDK. And I can't repro the issue with differen zone on my side.The only way I get the exception is that local device system is incorrect.

enter image description here

So I assume that the exception is caused by the device using incorrect time.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Tom! Really the exception just appears when the device time is incorrect. I treated the exception showing a friendly message to user suggesting the date/time corretion, but for me, still is a mistery about how is the process to create a token. As there is no server in the middle, just the SDK connecting in Azure How the SDK knows that my device is one hour late? But, either way, thanks for the help
SDK need to get the device local time and then covert to UTC time (UTC is Coordinated Universal Time standard commonly used across the world) to generate token.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.