TheDude
TheDude

Reputation: 1531

How can I parse the expiration date from a Windows Azure SAS key as a client?

I'm trying to check on the expiration date of the SAS key on the client side so that I can request a new SAS key once it expires. I'm using the Microsoft.WindowsAzure.Storage namespace (which is version 2.0 of the azure storage library). Is there a built in method for this or will I have to parse it manually?

Upvotes: 4

Views: 2690

Answers (2)

kwill
kwill

Reputation: 11008

David's answer is correct for the question about how to parse the expiry time (+1). But ultimately you should not be doing this. There are two better options:

  1. The client should attempt to access the resource and then handle the authentication failure by requesting a new SAS.
  2. Provide a method for the client to determine the SAS expiry time, and the client would then keep track of this time and do a refresh at some interval before the expiry. An example of this is shown at http://blogs.msdn.com/b/windowsazurestorage/archive/2012/06/12/introducing-table-sas-shared-access-signature-queue-sas-and-update-to-blob-sas.aspx.

Upvotes: 2

David Makogon
David Makogon

Reputation: 71101

I don't believe there's anything specific in the storage client library. You should be able to parse the querystring on the URI and look at the UTC date in signedexpiry. You can parse the querystring with HttpUtility.ParseQueryString().

Here are two caveats to think about:

  • This check won't be entirely accurate, since there could be clock-drift between your machine's clock and the Storage service's clock.
  • If the server uses a shared access policy (which allows for programmatic modification/revocation of access), there's no guarantee that signedexpiry will be part of the querystring. More on shared access policies here.

Upvotes: 3

Related Questions