Skip to content

Instantly share code, notes, and snippets.

@Scooletz
Created March 17, 2018 14:48
Show Gist options
  • Save Scooletz/5b3d55ef5e5bc7857b3d23bde22dc629 to your computer and use it in GitHub Desktop.
Save Scooletz/5b3d55ef5e5bc7857b3d23bde22dc629 to your computer and use it in GitHub Desktop.
Blob SAS Token
public static string GetBlobReadonlySasToken(CloudStorageAccount account)
{
var now = DateTimeOffset.Now;
// to address emulator running on http
var nonHttps = account.BlobEndpoint.ToString().StartsWith("http:");
var sas = account.GetSharedAccessSignature(new SharedAccessAccountPolicy
{
Services = SharedAccessAccountServices.Blob,
Permissions = SharedAccessAccountPermissions.List | SharedAccessAccountPermissions.Read,
ResourceTypes = SharedAccessAccountResourceTypes.Container | SharedAccessAccountResourceTypes.Object | SharedAccessAccountResourceTypes.Service,
Protocols = nonHttps ? SharedAccessProtocol.HttpsOrHttp : SharedAccessProtocol.HttpsOnly,
SharedAccessStartTime = now.AddMinutes(-15),
SharedAccessExpiryTime = now.AddMinutes(30),
});
return account.BlobEndpoint + sas;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment