/// <inheritdoc /> public async override Task <StorageToken> GetAccessTokenAsync(StorageTokenRequest request, StorageTokenScope scope, IContainerNameResolver containerNameResolver) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (containerNameResolver == null) { throw new ArgumentNullException(nameof(containerNameResolver)); } string containerName = await containerNameResolver.GetFileContainerNameAsync(request.TargetFile.TableName, request.TargetFile.ParentId, request.TargetFile.Name); CloudBlobContainer container = GetContainer(containerName); var constraints = new SharedAccessBlobPolicy(); constraints.SharedAccessExpiryTime = DateTime.UtcNow.AddHours(1); constraints.Permissions = GetBlobAccessPermissions(request.Permissions); string sas = null; Uri resourceUri = null; if (scope == StorageTokenScope.File) { CloudBlockBlob blob = container.GetBlockBlobReference(request.TargetFile.Name); resourceUri = blob.Uri; sas = blob.GetSharedAccessSignature(constraints); } else if (scope == StorageTokenScope.Record) { resourceUri = container.Uri; sas = container.GetSharedAccessSignature(constraints); } var storageToken = new StorageToken(resourceUri, request.TargetFile.ParentId, request.Permissions, scope, sas); return(storageToken); }
/// <summary> /// Retrieves an access token for a given request. /// </summary> /// <param name="request">The request the requested access </param> /// <param name="scope"></param> /// <param name="containerNameResolver">The instance of an <see cref="IContainerNameResolver"/> used to resolve the storage container name.</param> /// <returns>A <see cref="Task{StorageToken}"/> that completes when the storage token is generated.</returns> abstract public Task <StorageToken> GetAccessTokenAsync(StorageTokenRequest request, StorageTokenScope scope, IContainerNameResolver containerNameResolver);