public DropboxDestination(IDropboxConfiguration dropboxPluginConfiguration, IDropboxLanguage dropboxLanguage) { _dropboxPluginConfiguration = dropboxPluginConfiguration; _dropboxLanguage = dropboxLanguage; _oAuth2Settings = new OAuth2Settings { AuthorizationUri = DropboxApiUri. AppendSegments("1", "oauth2", "authorize"). ExtendQuery(new Dictionary <string, string> { { "response_type", "code" }, { "client_id", "{ClientId}" }, { "redirect_uri", "{RedirectUrl}" }, { "state", "{State}" } }), TokenUrl = DropboxApiUri.AppendSegments("1", "oauth2", "token"), CloudServiceName = "Dropbox", ClientId = dropboxPluginConfiguration.ClientId, ClientSecret = dropboxPluginConfiguration.ClientSecret, AuthorizeMode = AuthorizeModes.LocalhostServer, RedirectUrl = "http://localhost:47336", Token = dropboxPluginConfiguration }; _oAuthHttpBehaviour = OAuth2HttpBehaviourFactory.Create(_oAuth2Settings); }
/// <summary> /// Do the actual upload to OneDrive /// </summary> /// <param name="oAuth2Settings">OAuth2Settings</param> /// <param name="surfaceToUpload">ISurface to upload</param> /// <param name="progress">IProgress</param> /// <param name="token">CancellationToken</param> /// <returns>OneDriveUploadResponse with details</returns> private async Task <OneDriveUploadResponse> UploadToOneDriveAsync(OAuth2Settings oAuth2Settings, ISurface surfaceToUpload, IProgress <int> progress = null, CancellationToken token = default) { var filename = surfaceToUpload.GenerateFilename(CoreConfiguration, _oneDriveConfiguration); var uploadUri = OneDriveUri.AppendSegments("root:", "Screenshots", filename + ":", "content"); var localBehaviour = _oneDriveHttpBehaviour.ShallowClone(); if (progress != null) { localBehaviour.UploadProgress = percent => { UiContext.RunOn(() => progress.Report((int)(percent * 100)), token); }; } var oauthHttpBehaviour = OAuth2HttpBehaviourFactory.Create(oAuth2Settings, localBehaviour); using (var imageStream = new MemoryStream()) { surfaceToUpload.WriteToStream(imageStream, CoreConfiguration, _oneDriveConfiguration); imageStream.Position = 0; using (var content = new StreamContent(imageStream)) { content.Headers.Add("Content-Type", surfaceToUpload.GenerateMimeType(CoreConfiguration, _oneDriveConfiguration)); oauthHttpBehaviour.MakeCurrent(); return(await uploadUri.PutAsync <OneDriveUploadResponse>(content, token)); } } }
/// <summary> /// Do the actual upload to OneDrive /// </summary> /// <param name="oAuth2Settings">OAuth2Settings</param> /// <param name="surfaceToUpload">ISurface to upload</param> /// <param name="outputSettings">OutputSettings for the image file format</param> /// <param name="title">Title</param> /// <param name="filename">Filename</param> /// <param name="progress">IProgress</param> /// <param name="token">CancellationToken</param> /// <returns>ImgurInfo with details</returns> public static async Task <OneDriveUploadResponse> UploadToOneDriveAsync(OAuth2Settings oAuth2Settings, ISurface surfaceToUpload, SurfaceOutputSettings outputSettings, string title, string filename, IProgress <int> progress = null, CancellationToken token = default) { var uploadUri = new Uri(UrlUtils.GetUploadUrl(filename)); var localBehaviour = Behaviour.ShallowClone(); if (progress != null) { localBehaviour.UploadProgress = percent => { UiContext.RunOn(() => progress.Report((int)(percent * 100)), token); }; } var oauthHttpBehaviour = OAuth2HttpBehaviourFactory.Create(oAuth2Settings, localBehaviour); using (var imageStream = new MemoryStream()) { ImageOutput.SaveToStream(surfaceToUpload, imageStream, outputSettings); imageStream.Position = 0; using (var content = new StreamContent(imageStream)) { content.Headers.Add("Content-Type", "image/" + outputSettings.Format); oauthHttpBehaviour.MakeCurrent(); return(await uploadUri.PostAsync <OneDriveUploadResponse>(content, token)); } } }
public ImgurOAuth2Tests(ITestOutputHelper testOutputHelper) { LogSettings.RegisterDefaultLogger <XUnitLogger>(LogLevels.Verbose, testOutputHelper); var oAuth2Settings = new OAuth2Settings { AuthorizationUri = ApiUri.AppendSegments("oauth2", "authorize"). ExtendQuery(new Dictionary <string, string> { { "response_type", "code" }, { "client_id", "{ClientId}" }, { "redirect_uri", "{RedirectUrl}" }, // TODO: Add version? { "state", "{State}" } }), TokenUrl = ApiUri.AppendSegments("oauth2", "token"), CloudServiceName = "Imgur", ClientId = ClientId, ClientSecret = ClientSecret, RedirectUrl = "https://getgreenshot.org/oauth/imgur", AuthorizeMode = AuthorizeModes.OutOfBoundAuto }; var behavior = new HttpBehaviour { JsonSerializer = new JsonNetJsonSerializer(), OnHttpClientCreated = httpClient => { httpClient.SetAuthorization("Client-ID", ClientId); httpClient.DefaultRequestHeaders.ExpectContinue = false; } }; _oAuthHttpBehaviour = OAuth2HttpBehaviourFactory.Create(oAuth2Settings, behavior); }
private async Task <OneDriveGetLinkResponse> CreateSharableLinkAync(OAuth2Settings oAuth2Settings, string imageId, OneDriveLinkType oneDriveLinkType) { var sharableLink = OneDriveUri.AppendSegments("items", imageId, "createLink"); var localBehaviour = _oneDriveHttpBehaviour.ShallowClone(); var oauthHttpBehaviour = OAuth2HttpBehaviourFactory.Create(oAuth2Settings, localBehaviour); oauthHttpBehaviour.MakeCurrent(); var body = new OneDriveGetLinkRequest(); body.Scope = oneDriveLinkType == OneDriveLinkType.@public ? "anonymous" : "organization"; body.Type = "view"; return(await sharableLink.PostAsync <OneDriveGetLinkResponse>(body)); }
public DropboxDestination( IDropboxConfiguration dropboxPluginConfiguration, IDropboxLanguage dropboxLanguage, INetworkConfiguration networkConfiguration, IResourceProvider resourceProvider, ICoreConfiguration coreConfiguration, IGreenshotLanguage greenshotLanguage, Func <CancellationTokenSource, Owned <PleaseWaitForm> > pleaseWaitFormFactory ) : base(coreConfiguration, greenshotLanguage) { _dropboxPluginConfiguration = dropboxPluginConfiguration; _dropboxLanguage = dropboxLanguage; _resourceProvider = resourceProvider; _pleaseWaitFormFactory = pleaseWaitFormFactory; _oAuth2Settings = new OAuth2Settings { AuthorizationUri = DropboxApiUri. AppendSegments("1", "oauth2", "authorize"). ExtendQuery(new Dictionary <string, string> { { "response_type", "code" }, { "client_id", "{ClientId}" }, { "redirect_uri", "{RedirectUrl}" }, { "state", "{State}" } }), TokenUrl = DropboxApiUri.AppendSegments("1", "oauth2", "token"), CloudServiceName = "Dropbox", ClientId = dropboxPluginConfiguration.ClientId, ClientSecret = dropboxPluginConfiguration.ClientSecret, AuthorizeMode = AuthorizeModes.LocalhostServer, RedirectUrl = "http://localhost:47336", Token = dropboxPluginConfiguration }; var httpBehaviour = OAuth2HttpBehaviourFactory.Create(_oAuth2Settings); _oAuthHttpBehaviour = httpBehaviour; // Use the default network settings httpBehaviour.HttpSettings = networkConfiguration; }
public OAuth2Tests(ITestOutputHelper testOutputHelper) { LogSettings.RegisterDefaultLogger <XUnitLogger>(LogLevels.Verbose, testOutputHelper); var oAuth2Settings = new OAuth2Settings { ClientId = "<client id from google developer console>", ClientSecret = "<client secret from google developer console>", CloudServiceName = "Google", AuthorizeMode = AuthorizeModes.LocalhostServer, TokenUrl = GoogleApiUri.AppendSegments("oauth2", "v4", "token"), AuthorizationUri = new Uri("https://accounts.google.com").AppendSegments("o", "oauth2", "v2", "auth") .ExtendQuery(new Dictionary <string, string> { { "response_type", "code" }, { "client_id", "{ClientId}" }, { "redirect_uri", "{RedirectUrl}" }, { "state", "{State}" }, { "scope", GoogleApiUri.AppendSegments("auth", "calendar").AbsoluteUri } }) }; _oAuthHttpBehaviour = OAuth2HttpBehaviourFactory.Create(oAuth2Settings); }
/// <summary> /// Do the actual upload to Picasa /// </summary> /// <param name="oAuth2Settings">OAuth2Settings</param> /// <param name="surfaceToUpload">ICapture</param> /// <param name="otherParameters">IDictionary</param> /// <param name="progress">IProgress</param> /// <param name="token"></param> /// <returns>PicasaResponse</returns> public async Task <ImgurImage> AuthenticatedUploadToImgurAsync(OAuth2Settings oAuth2Settings, ISurface surfaceToUpload, IDictionary <string, string> otherParameters, IProgress <int> progress = null, CancellationToken token = default) { var uploadUri = new Uri(_imgurConfiguration.ApiUrl).AppendSegments("upload.json").ExtendQuery(otherParameters); var localBehaviour = Behaviour.ShallowClone(); if (progress != null) { localBehaviour.UploadProgress = percent => { UiContext.RunOn(() => progress.Report((int)(percent * 100)), token); }; } var oauthHttpBehaviour = OAuth2HttpBehaviourFactory.Create(oAuth2Settings, localBehaviour); using (var imageStream = new MemoryStream()) { surfaceToUpload.WriteToStream(imageStream, _coreConfiguration, _imgurConfiguration); imageStream.Position = 0; using (var content = new StreamContent(imageStream)) { content.Headers.Add("Content-Type", surfaceToUpload.GenerateMimeType(_coreConfiguration, _imgurConfiguration)); oauthHttpBehaviour.MakeCurrent(); return(await uploadUri.PostAsync <ImgurImage>(content, token).ConfigureAwait(false)); } } }