public string GetAuthorizationURL() { Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("response_type", "code"); args.Add("client_id", AuthInfo.Client_ID); return(URLHelpers.CreateQuery(URLOAuth2Authorize, args)); }
public string GetAuthorizationURL() { Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("response_type", "code"); args.Add("client_id", AuthInfo.Client_ID); return(URLHelpers.CreateQuery("https://www.box.com/api/oauth2/authorize", args)); }
public string GetAuthorizationURL() { Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("client_id", AuthInfo.Client_ID); args.Add("redirect_uri", Links.URL_CALLBACK); return(URLHelpers.CreateQuery("https://bitly.com/oauth/authorize", args)); }
protected HttpWebResponse GetResponse(HttpMethod method, string url, Stream data = null, string contentType = null, Dictionary <string, string> args = null, NameValueCollection headers = null, CookieCollection cookies = null, bool allowNon2xxResponses = false) { IsUploading = true; StopUploadRequested = false; try { url = URLHelpers.CreateQuery(url, args); long contentLength = 0; if (data != null) { contentLength = data.Length; } HttpWebRequest request = UploadHelpers.CreateWebRequest(method, url, headers, cookies, contentType, contentLength); currentRequest = request; if (contentLength > 0) { using (Stream requestStream = request.GetRequestStream()) { if (!TransferData(data, requestStream)) { return(null); } } } return((HttpWebResponse)request.GetResponse()); } catch (WebException we) when(we.Response != null && allowNon2xxResponses) { // if we.Response != null, then the request was successful, but // returned a non-200 status code return(we.Response as HttpWebResponse); } catch (Exception e) { if (!StopUploadRequested) { AddWebError(e, url); } } finally { currentRequest = null; IsUploading = false; } return(null); }
public Ge_ttShare CreateShare(string accessToken) { Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("accesstoken", accessToken); string url = URLHelpers.CreateQuery(URLHelpers.CombineURL(APIURL, "shares/create"), args); string response = SendRequest(HttpMethod.POST, url); return(JsonConvert.DeserializeObject <Ge_ttShare>(response)); }
public string GetAuthorizationURL() { Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("response_type", "code"); args.Add("client_id", AuthInfo.Client_ID); args.Add("redirect_uri", "urn:ietf:wg:oauth:2.0:oob"); args.Add("scope", "https://www.googleapis.com/auth/drive"); return(URLHelpers.CreateQuery("https://accounts.google.com/o/oauth2/auth", args)); }
public string GetAuthorizationURL() { Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("response_type", "code"); args.Add("client_id", AuthInfo.Client_ID); args.Add("redirect_uri", RedirectMethod); args.Add("scope", Scope); return(URLHelpers.CreateQuery(AuthorizationEndpoint, args)); }
public string GetAuthorizationURL() { Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("client_id", AuthInfo.Client_ID); args.Add("scope", "wl.offline_access wl.skydrive_update"); args.Add("response_type", "code"); args.Add("redirect_uri", Links.URL_CALLBACK); return(URLHelpers.CreateQuery("https://login.live.com/oauth20_authorize.srf", args)); }
public string GetAuthorizationURL() { Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("client_id", AuthInfo.Client_ID); args.Add("scope", "all"); args.Add("state", "ShareX"); args.Add("response_type", "code"); args.Add("redirect_uri", Links.URL_CALLBACK); return(URLHelpers.CreateQuery(URL_AUTHORIZE, args)); }
public string GetAuthorizationURL() { Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("client_id", AuthInfo.Client_ID); args.Add("scope", "offline_access files.readwrite"); args.Add("response_type", "code"); args.Add("redirect_uri", Links.URL_CALLBACK); if (AuthInfo.Proof != null) { args.Add("code_challenge", AuthInfo.Proof.CodeChallenge); args.Add("code_challenge_method", AuthInfo.Proof.ChallengeMethod); } return(URLHelpers.CreateQuery(AuthorizationEndpoint, args)); }
private HttpWebResponse GetResponse(HttpMethod method, string url, Stream data = null, string contentType = null, Dictionary <string, string> args = null, NameValueCollection headers = null, CookieCollection cookies = null) { IsUploading = true; StopUploadRequested = false; try { url = URLHelpers.CreateQuery(url, args); long length = 0; if (data != null) { length = data.Length; } HttpWebRequest request = PrepareWebRequest(method, url, headers, cookies, contentType, length); if (length > 0) { using (Stream requestStream = request.GetRequestStream()) { if (!TransferData(data, requestStream)) { return(null); } } } return((HttpWebResponse)request.GetResponse()); } catch (Exception e) { if (!StopUploadRequested) { AddWebError(e, url); } } finally { currentRequest = null; IsUploading = false; } return(null); }
public override UploadResult Upload(Stream stream, string fileName) { if (!CheckAuthorization()) { return(null); } Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("access_token", AuthInfo.Token.access_token); args.Add("overwrite", "true"); args.Add("downsize_photo_uploads", "false"); string folderPath; if (!string.IsNullOrEmpty(FolderID)) { folderPath = URLHelpers.CombineURL(FolderID, "files"); } else { folderPath = "me/skydrive/files"; } string url = URLHelpers.CreateQuery(URLHelpers.CombineURL("https://apis.live.net/v5.0", folderPath), args); UploadResult result = SendRequestFile(url, stream, fileName); if (result.IsSuccess) { OneDriveFileInfo uploadInfo = JsonConvert.DeserializeObject <OneDriveFileInfo>(result.Response); if (AutoCreateShareableLink) { result.URL = CreateShareableLink(uploadInfo.id); } else { result.URL = uploadInfo.source; } } return(result); }
private string SimpleUpload(Stream stream, string fileName) { Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("session_token", sessionToken); args.Add("path", UploadPath); args.Add("response_format", "json"); args.Add("signature", GetSignature("upload/simple.php", args)); string url = URLHelpers.CreateQuery(apiUrl + "upload/simple.php", args); UploadResult res = SendRequestFile(url, stream, fileName, "Filedata"); if (!res.IsSuccess) { throw new IOException(res.ErrorsToString()); } SimpleUploadResponse resp = DeserializeResponse <SimpleUploadResponse>(res.Response); EnsureSuccess(resp); if (resp.doupload.result != 0 || resp.doupload.key == null) { throw new IOException("Invalid response"); } return(resp.doupload.key); }
public override UploadResult Upload(Stream stream, string fileName) { bool forcePathStyle = Settings.UsePathStyle; if (!forcePathStyle && Settings.Bucket.Contains(".")) { forcePathStyle = true; } string endpoint = URLHelpers.RemovePrefixes(Settings.Endpoint); string host = forcePathStyle ? endpoint : $"{Settings.Bucket}.{endpoint}"; string algorithm = "AWS4-HMAC-SHA256"; string credentialDate = DateTime.UtcNow.ToString("yyyyMMdd", CultureInfo.InvariantCulture); string region = GetRegion(); string scope = URLHelpers.CombineURL(credentialDate, region, "s3", "aws4_request"); string credential = URLHelpers.CombineURL(Settings.AccessKeyID, scope); string longDate = DateTime.UtcNow.ToString("yyyyMMddTHHmmssZ", CultureInfo.InvariantCulture); string expiresTotalSeconds = ((long)TimeSpan.FromHours(1).TotalSeconds).ToString(); string contentType = Helpers.GetMimeType(fileName); NameValueCollection headers = new NameValueCollection(); headers["content-type"] = contentType; headers["host"] = host; if (Settings.SetPublicACL) { headers["x-amz-acl"] = "public-read"; } headers["x-amz-storage-class"] = Settings.StorageClass.ToString(); string signedHeaders = GetSignedHeaders(headers); Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("X-Amz-Algorithm", algorithm); args.Add("X-Amz-Credential", credential); args.Add("X-Amz-Date", longDate); args.Add("X-Amz-Expires", expiresTotalSeconds); args.Add("X-Amz-SignedHeaders", signedHeaders); string uploadPath = GetUploadPath(fileName); string canonicalURI = uploadPath; if (forcePathStyle) { canonicalURI = URLHelpers.CombineURL(Settings.Bucket, canonicalURI); } canonicalURI = URLHelpers.AddSlash(canonicalURI, SlashType.Prefix); canonicalURI = URLHelpers.URLPathEncode(canonicalURI); string canonicalQueryString = URLHelpers.CreateQuery(args, true); string canonicalHeaders = CreateCanonicalHeaders(headers); string canonicalRequest = "PUT" + "\n" + canonicalURI + "\n" + canonicalQueryString + "\n" + canonicalHeaders + "\n" + signedHeaders + "\n" + "UNSIGNED-PAYLOAD"; string stringToSign = algorithm + "\n" + longDate + "\n" + scope + "\n" + Helpers.BytesToHex(Helpers.ComputeSHA256(canonicalRequest)); byte[] dateKey = Helpers.ComputeHMACSHA256(credentialDate, "AWS4" + Settings.SecretAccessKey); byte[] dateRegionKey = Helpers.ComputeHMACSHA256(region, dateKey); byte[] dateRegionServiceKey = Helpers.ComputeHMACSHA256("s3", dateRegionKey); byte[] signingKey = Helpers.ComputeHMACSHA256("aws4_request", dateRegionServiceKey); string signature = Helpers.BytesToHex(Helpers.ComputeHMACSHA256(stringToSign, signingKey)); args.Add("X-Amz-Signature", signature); headers.Remove("content-type"); headers.Remove("host"); string url = URLHelpers.CombineURL(host, canonicalURI); url = URLHelpers.CreateQuery(url, args, true); url = URLHelpers.ForcePrefix(url, "https://"); NameValueCollection responseHeaders = SendRequestGetHeaders(HttpMethod.PUT, url, stream, contentType, null, headers); if (responseHeaders == null || responseHeaders.Count == 0) { Errors.Add("Upload to Amazon S3 failed. Check your access credentials."); return(null); } if (responseHeaders["ETag"] == null) { Errors.Add("Upload to Amazon S3 failed."); return(null); } return(new UploadResult { IsSuccess = true, URL = GenerateURL(uploadPath) }); }
protected UploadResult SendRequestFileRange(string url, Stream data, string fileName, long contentPosition = 0, long contentLength = -1, Dictionary <string, string> args = null, NameValueCollection headers = null, CookieCollection cookies = null, ResponseType responseType = ResponseType.Text, HttpMethod method = HttpMethod.PUT) { UploadResult result = new UploadResult(); IsUploading = true; StopUploadRequested = false; try { url = URLHelpers.CreateQuery(url, args); if (contentLength == -1) { contentLength = data.Length; } contentLength = Math.Min(contentLength, data.Length - contentPosition); string contentType = UploadHelpers.GetMimeType(fileName); if (headers == null) { headers = new NameValueCollection(); } long startByte = contentPosition; long endByte = startByte + contentLength - 1; long dataLength = data.Length; headers.Add("Content-Range", $"bytes {startByte}-{endByte}/{dataLength}"); HttpWebRequest request = UploadHelpers.CreateWebRequest(method, url, headers, cookies, contentType, contentLength); currentRequest = request; using (Stream requestStream = request.GetRequestStream()) { if (!TransferData(data, requestStream, contentPosition, contentLength)) { return(null); } } using (WebResponse response = request.GetResponse()) { result.Response = UploadHelpers.ResponseToString(response, responseType); } result.IsSuccess = true; } catch (Exception e) { if (!StopUploadRequested) { string response = AddWebError(e, url); if (ReturnResponseOnError && e is WebException) { result.Response = response; } } } finally { currentRequest = null; IsUploading = false; if (VerboseLogs && !string.IsNullOrEmpty(VerboseLogsPath)) { WriteVerboseLog(url, args, headers, result.Response); } } return(result); }