/// <summary> /// Gets a storage token for the given entity ID and <see cref="StorageTokenRequest"/>, using the provided <see cref="IContainerNameResolver"/>. /// </summary> /// <param name="id">The entity id.</param> /// <param name="value">The request provided by the client.</param> /// <param name="containerNameResolver">The instance of an <see cref="IContainerNameResolver"/> used to resolve the storage container name.</param> /// <returns></returns> public virtual async Task <StorageToken> GetStorageTokenAsync(string id, StorageTokenRequest value, IContainerNameResolver containerNameResolver) { StorageTokenScope scope = GetStorageScopeForRequest(id, value); StorageToken token = await this.storageProvider.GetAccessTokenAsync(value, scope, containerNameResolver); return(token); }
// return a storage token that can be used for blob upload or download public async Task <HttpResponseMessage> PostStorageTokenRequest(string id, StorageTokenRequest request) { // The file size is encoded in the start of the filename, lg, md, etc. // If it doesn't match the pattern then the default size of lg is used var requestedSize = request.TargetFile.Name.Substring(0, 2); StorageToken token = await GetStorageTokenAsync(id, request, new ImageNameResolver(requestedSize)); return(Request.CreateResponse(token)); }
private async Task <StorageToken> GetStorageToken(IMobileServiceClient client, MobileServiceFile file, StoragePermissions permissions) { var tokenRequest = new StorageTokenRequest(); tokenRequest.Permissions = permissions; tokenRequest.TargetFile = file; string route = string.Format("/tables/{0}/{1}/StorageToken", file.TableName, file.ParentId); return(await this.client.InvokeApiAsync <StorageTokenRequest, StorageToken>(route, tokenRequest)); }
public async Task <HttpResponseMessage> PostStorageTokenRequest(string id, StorageTokenRequest request) { var currentUserId = AuthenticationHelper.GetUserId(Request, User); if (!claimsDbContext.Claims.Any(i => i.Id == id && i.UserId == currentUserId)) { Request.CreateBadRequestResponse(ErrorMessage); } var token = await GetStorageTokenAsync(id, request, containerNameResolver); return(Request.CreateResponse(token)); }
public async Task <HttpResponseMessage> PostStorageTokenRequest(string id, StorageTokenRequest value) { StorageToken token = await GetStorageTokenAsync(id, value); return(Request.CreateResponse(token)); }
/// <summary> /// Gets a storage token for the given entity ID and <see cref="StorageTokenRequest"/>. /// </summary> /// <param name="id">The entity id.</param> /// <param name="value">The request provided by the client.</param> /// <returns></returns> public Task <StorageToken> GetStorageTokenAsync(string id, StorageTokenRequest value) { return(GetStorageTokenAsync(id, value, new ContainerNameResolver())); }
/// <summary> /// Resolves the storage token scope for a given request. /// </summary> /// <param name="id">The entity id.</param> /// <param name="value">The request provided by the client.</param> /// <returns>The resolved scope, based on the provided parameters. The default implementation ALWAYS returns <see cref="StorageTokenScope.Record"/>.</returns> protected virtual StorageTokenScope GetStorageScopeForRequest(string id, StorageTokenRequest value) { return(StorageTokenScope.Record); }
// return a storage token that can be used for blob upload or download public async Task <HttpResponseMessage> PostStorageTokenRequest(string id, StorageTokenRequest request) { StorageToken token = await GetStorageTokenAsync(id, request, new ImageNameResolver(request.TargetFile.StoreUri)); return(Request.CreateResponse(token)); }
public async Task <IHttpActionResult> PostStorageTokenRequest(string id, StorageTokenRequest value) { StorageToken token = await GetStorageTokenAsync(id, value); return(Ok(token)); }
public async Task <HttpResponseMessage> StorageToken(string id, StorageTokenRequest value) => Request.CreateResponse(await GetStorageTokenAsync(id, value));