/// <summary> /// Get a down scoped token. /// </summary> /// <returns>The down scoped access token.</returns> public string Exchange() { BoxRequest boxRequest = new BoxRequest(new Uri(Constants.BoxApiHostUriString), Constants.AuthTokenEndpointString) .Method(RequestMethod.Post) .Payload(Constants.RequestParameters.SubjectToken, token) .Payload(Constants.RequestParameters.SubjectTokenType, Constants.RequestParameters.AccessTokenTypeValue) .Payload(Constants.RequestParameters.Scope, scope) .Payload(Constants.RequestParameters.Resource, resourceUrl) .Payload(Constants.RequestParameters.GrantType, Constants.RequestParameters.TokenExchangeGrantTypeValue); if (actorToken != null) { boxRequest = boxRequest.Payload(Constants.RequestParameters.ActorToken, actorToken) .Payload(Constants.RequestParameters.ActorTokenType, Constants.RequestParameters.IdTokenTypeValue); } var handler = new HttpRequestHandler(); var converter = new BoxJsonConverter(); var service = new BoxService(handler); IBoxResponse <OAuthSession> boxResponse = service.ToResponseAsync <OAuthSession>(boxRequest).Result; boxResponse.ParseResults(converter); return(boxResponse.ResponseObject.AccessToken); }
/// <summary> /// Get a down scoped token. /// </summary> /// <returns>The down scoped access token.</returns> public string Exchange() { BoxRequest boxRequest = new BoxRequest(new Uri(Constants.BoxApiHostUriString), Constants.AuthTokenEndpointString) .Method(RequestMethod.Post) .Payload(Constants.RequestParameters.SubjectToken, token) .Payload(Constants.RequestParameters.SubjectTokenType, Constants.RequestParameters.AccessTokenTypeValue) .Payload(Constants.RequestParameters.Scope, scope) .Payload(Constants.RequestParameters.Resource, resourceUrl) .Payload(Constants.RequestParameters.GrantType, Constants.RequestParameters.TokenExchangeGrantTypeValue); if (actorToken != null) { boxRequest = boxRequest.Payload(Constants.RequestParameters.ActorToken, actorToken) .Payload(Constants.RequestParameters.ActorTokenType, Constants.RequestParameters.IdTokenTypeValue); } var handler = new HttpRequestHandler(); var converter = new BoxJsonConverter(); var service = new BoxService(handler); IBoxResponse<OAuthSession> boxResponse = service.ToResponseAsync<OAuthSession>(boxRequest).Result; boxResponse.ParseResults(converter); return boxResponse.ResponseObject.AccessToken; }
/// <summary> /// Used to create a copy of a file in another folder. The original version of the file will not be altered. /// </summary> /// <param name="fileRequest">BoxFileRequest object.</param> /// <param name="fields">Attribute(s) to include in the response.</param> /// <returns> /// A full file object is returned if the ID is valid and if the update is successful. /// Errors can be thrown if the destination folder is invalid or if a file-name collision occurs. /// </returns> public async Task <BoxFile> CopyAsync(BoxFileRequest fileRequest, List <string> fields = null) { fileRequest.ThrowIfNull("fileRequest"); fileRequest.Id.ThrowIfNullOrWhiteSpace("fileRequest.Id"); fileRequest.Parent.ThrowIfNull("fileRequest.Parent") .Id.ThrowIfNullOrWhiteSpace("fileRequest.Parent.Id"); BoxRequest request = new BoxRequest(_config.FilesEndpointUri, string.Format(Constants.CopyPathString, fileRequest.Id)) .Method(RequestMethod.Post) .Param(ParamFields, fields); fileRequest.Id = null; //file Id was used as a query parameter in this case request.Payload(_converter.Serialize(fileRequest)); IBoxResponse <BoxFile> response = await ToResponseAsync <BoxFile>(request).ConfigureAwait(false); return(response.ResponseObject); }
/// <summary> /// Restores an item that has been moved to the trash. Default behavior is to restore the item to the folder it was in /// before it was moved to the trash. If that parent folder no longer exists or if there is now an item with the same /// name in that parent folder, the new parent folder and/or new name will need to be included in the request. /// </summary> /// <param name="folderRequest">BoxFolderRequest object (specify Parent.Id if you wish to restore to a different parent)</param> /// <param name="fields">Attribute(s) to include in the response</param> /// <returns>The full item will be returned if success. By default it is restored to the parent folder it was in before it was trashed.</returns> public async Task <BoxFolder> RestoreTrashedFolderAsync(BoxFolderRequest folderRequest, List <string> fields = null) { folderRequest.ThrowIfNull("folderRequest") .Id.ThrowIfNullOrWhiteSpace("folderRequest.Id"); BoxRequest request = new BoxRequest(_config.FoldersEndpointUri, folderRequest.Id) .Method(RequestMethod.Post) .Param(ParamFields, fields); // ID shall not be used in request body it is used only as url attribute string oldId = folderRequest.Id; folderRequest.Id = null; request.Payload(_converter.Serialize(folderRequest)); folderRequest.Id = oldId; IBoxResponse <BoxFolder> response = await ToResponseAsync <BoxFolder>(request).ConfigureAwait(false); return(response.ResponseObject); }
/// <summary> /// Used to create a copy of a file in another folder. The original version of the file will not be altered. /// </summary> /// <param name="fileRequest">BoxFileRequest object.</param> /// <param name="fields">Attribute(s) to include in the response.</param> /// <returns> /// A full file object is returned if the ID is valid and if the update is successful. /// Errors can be thrown if the destination folder is invalid or if a file-name collision occurs. /// </returns> public async Task<BoxFile> CopyAsync(BoxFileRequest fileRequest, List<string> fields = null) { fileRequest.ThrowIfNull("fileRequest"); fileRequest.Id.ThrowIfNullOrWhiteSpace("fileRequest.Id"); fileRequest.Parent.ThrowIfNull("fileRequest.Parent") .Id.ThrowIfNullOrWhiteSpace("fileRequest.Parent.Id"); BoxRequest request = new BoxRequest(_config.FilesEndpointUri, string.Format(Constants.CopyPathString, fileRequest.Id)) .Method(RequestMethod.Post) .Param(ParamFields, fields); fileRequest.Id = null; //file Id was used as a query parameter in this case request.Payload(_converter.Serialize(fileRequest)); IBoxResponse<BoxFile> response = await ToResponseAsync<BoxFile>(request).ConfigureAwait(false); return response.ResponseObject; }
/// <summary> /// Restores an item that has been moved to the trash. Default behavior is to restore the item to the folder it was in /// before it was moved to the trash. If that parent folder no longer exists or if there is now an item with the same /// name in that parent folder, the new parent folder and/or new name will need to be included in the request. /// </summary> /// <param name="folderRequest">BoxFolderRequest object (specify Parent.Id if you wish to restore to a different parent)</param> /// <param name="fields">Attribute(s) to include in the response</param> /// <returns>The full item will be returned if success. By default it is restored to the parent folder it was in before it was trashed.</returns> public async Task<BoxFolder> RestoreTrashedFolderAsync(BoxFolderRequest folderRequest, List<string> fields = null) { folderRequest.ThrowIfNull("folderRequest") .Id.ThrowIfNullOrWhiteSpace("folderRequest.Id"); BoxRequest request = new BoxRequest(_config.FoldersEndpointUri, folderRequest.Id) .Method(RequestMethod.Post) .Param(ParamFields, fields); // ID shall not be used in request body it is used only as url attribute string oldId = folderRequest.Id; folderRequest.Id = null; request.Payload(_converter.Serialize(folderRequest)); folderRequest.Id = oldId; IBoxResponse<BoxFolder> response = await ToResponseAsync<BoxFolder>(request).ConfigureAwait(false); return response.ResponseObject; }