Created
March 17, 2018 14:48
-
-
Save Scooletz/5b3d55ef5e5bc7857b3d23bde22dc629 to your computer and use it in GitHub Desktop.
Blob SAS Token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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