/// <summary> /// Use an account's <see cref="TableSharedKeyCredential"/> to sign this /// shared access signature values to produce the proper SAS query /// parameters for authenticating requests. /// </summary> /// <param name="sharedKeyCredential"> /// The storage account's <see cref="TableSharedKeyCredential"/>. /// </param> /// <returns> /// An instance of <see cref="TableSasQueryParameters"/>. /// </returns> public TableSasQueryParameters ToSasQueryParameters(TableSharedKeyCredential sharedKeyCredential) { sharedKeyCredential = sharedKeyCredential ?? throw Errors.ArgumentNull(nameof(sharedKeyCredential)); EnsureState(); var startTime = SasExtensions.FormatTimesForSasSigning(StartsOn); var expiryTime = SasExtensions.FormatTimesForSasSigning(ExpiresOn); // String to sign: http://msdn.microsoft.com/en-us/library/azure/dn140255.aspx var stringToSign = string.Join("\n", Permissions, startTime, expiryTime, GetCanonicalName(sharedKeyCredential.AccountName, TableName), Identifier, IPRange.ToString(), SasExtensions.ToProtocolString(Protocol), Version, PartitionKeyStart, RowKeyStart, PartitionKeyEnd, RowKeyEnd); var signature = TableSharedKeyCredential.ComputeSasSignature(sharedKeyCredential, stringToSign); var p = new TableSasQueryParameters( version: Version, resourceTypes: default,
/// <summary> /// Use an account's <see cref="TableSharedKeyCredential"/> to sign this /// shared access signature values to produce the proper SAS query /// parameters for authenticating requests. /// </summary> /// <param name="sharedKeyCredential"> /// The storage account's <see cref="TableSharedKeyCredential"/>. /// </param> /// <returns> /// An instance of <see cref="TableAccountSasQueryParameters"/>. /// </returns> public TableAccountSasQueryParameters ToSasQueryParameters(TableSharedKeyCredential sharedKeyCredential) { sharedKeyCredential = sharedKeyCredential ?? throw Errors.ArgumentNull(nameof(sharedKeyCredential)); EnsureState(); var startTime = SasExtensions.FormatTimesForSasSigning(StartsOn); var expiryTime = SasExtensions.FormatTimesForSasSigning(ExpiresOn); // String to sign: https://docs.microsoft.com/en-us/rest/api/storageservices/create-account-sas#constructing-the-signature-string var stringToSign = string.Join("\n", sharedKeyCredential.AccountName, Permissions, TableConstants.Sas.TableAccountServices.Table, ResourceTypes.ToPermissionsString(), startTime, expiryTime, IPRange.ToString(), Protocol.ToProtocolString(), Version, ""); var signature = TableSharedKeyCredential.ComputeSasSignature(sharedKeyCredential, stringToSign); var p = new TableAccountSasQueryParameters( version: Version, resourceTypes: ResourceTypes, protocol: Protocol, startsOn: StartsOn, expiresOn: ExpiresOn, ipRange: IPRange, identifier: Identifier, resource: null, permissions: Permissions, signature: signature); return(p); }
/// <summary> /// Creates a new instance of the <see cref="TableAccountSasQueryParameters"/> /// type based on the supplied query parameters <paramref name="values"/>. /// All SAS-related query parameters will be removed from /// <paramref name="values"/>. /// </summary> /// <param name="values">URI query parameters</param> internal TableAccountSasQueryParameters( IDictionary <string, string> values) { // make copy, otherwise we'll get an exception when we remove IEnumerable <KeyValuePair <string, string> > kvps = values.ToArray(); foreach (KeyValuePair <string, string> kv in kvps) { // these are already decoded var isSasKey = true; switch (kv.Key.ToUpperInvariant()) { case TableConstants.Sas.Parameters.VersionUpper: _version = kv.Value; break; case TableConstants.Sas.Parameters.ResourceTypesUpper: _resourceTypes = SasExtensions.ParseResourceTypes(kv.Value); break; case TableConstants.Sas.Parameters.ProtocolUpper: _protocol = SasExtensions.ParseProtocol(kv.Value); break; case TableConstants.Sas.Parameters.StartTimeUpper: _startTime = DateTimeOffset.ParseExact(kv.Value, TableConstants.Sas.SasTimeFormat, CultureInfo.InvariantCulture); break; case TableConstants.Sas.Parameters.ExpiryTimeUpper: _expiryTime = DateTimeOffset.ParseExact(kv.Value, TableConstants.Sas.SasTimeFormat, CultureInfo.InvariantCulture); break; case TableConstants.Sas.Parameters.IPRangeUpper: _ipRange = SasIPRange.Parse(kv.Value); break; case TableConstants.Sas.Parameters.IdentifierUpper: _identifier = kv.Value; break; case TableConstants.Sas.Parameters.ResourceUpper: _resource = kv.Value; break; case TableConstants.Sas.Parameters.PermissionsUpper: _permissions = kv.Value; break; case TableConstants.Sas.Parameters.SignatureUpper: _signature = kv.Value; break; // We didn't recognize the query parameter default: isSasKey = false; break; } // Remove the query parameter if it's part of the SAS if (isSasKey) { values.Remove(kv.Key); } } }