简体   繁体   English

如何将Windows Azure SAS密钥作为客户端解析到期日期?

[英]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. 我正在尝试在客户端检查SAS密钥的到期日期,以便我可以在过期后请求新的SAS密钥。 I'm using the Microsoft.WindowsAzure.Storage namespace (which is version 2.0 of the azure storage library). 我正在使用Microsoft.WindowsAzure.Storage命名空间(Azure存储库的2.0版)。 Is there a built in method for this or will I have to parse it manually? 是否有内置的方法或者我必须手动解析它?

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 . 您应该能够解析URI上的querystring并在signedexpiry查看UTC日期。 You can parse the querystring with HttpUtility.ParseQueryString() . 您可以使用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. 如果服务器使用共享访问策略 (允许以编程方式修改/撤消访问权限),则不能保证signedexpiry将成为查询字符串的一部分。 More on shared access policies here . 有关共享访问策略的更多信息,请点击此处

David's answer is correct for the question about how to parse the expiry time (+1). 对于有关如何解析到期时间(+1)的问题,David的答案是正确的。 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. 客户端应尝试访问资源,然后通过请求新的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. 为客户端提供一种确定SAS过期时间的方法,然后客户端将跟踪该时间并在过期之前的某个时间间隔进行刷新。 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 . 例如, http://blogs.msdn.com/b/windowsazurestorage/archive/2012/06/12/introducing-table-sas-shared-access-signature-queue-sas-and-update-to -blob-sas.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM