public FlickrDestination(IFlickrConfiguration flickrConfiguration, IFlickrLanguage flickrLanguage) { _flickrConfiguration = flickrConfiguration; _flickrLanguage = flickrLanguage; _oAuthSettings = new OAuth1Settings { Token = flickrConfiguration, ClientId = flickrConfiguration.ClientId, ClientSecret = flickrConfiguration.ClientSecret, CloudServiceName = "Flickr", AuthorizeMode = AuthorizeModes.LocalhostServer, TokenUrl = FlickrOAuthUri.AppendSegments("request_token"), TokenMethod = HttpMethod.Post, AccessTokenUrl = FlickrOAuthUri.AppendSegments("access_token"), AccessTokenMethod = HttpMethod.Post, AuthorizationUri = FlickrOAuthUri.AppendSegments("authorize") .ExtendQuery(new Dictionary <string, string> { { OAuth1Parameters.Token.EnumValueOf(), "{RequestToken}" }, { OAuth1Parameters.Callback.EnumValueOf(), "{RedirectUrl}" } }), // Create a localhost redirect uri, prefer port 47336, but use the first free found RedirectUrl = new[] { 47336, 0 }.CreateLocalHostUri().AbsoluteUri, CheckVerifier = true }; _oAuthHttpBehaviour = OAuth1HttpBehaviourFactory.Create(_oAuthSettings); _oAuthHttpBehaviour.ValidateResponseContentType = false; }
/// <summary> /// Create a specify OAuth IHttpBehaviour /// </summary> /// <param name="oAuthSettings">OAuthSettings</param> /// <param name="fromHttpBehaviour">IHttpBehaviour or null</param> /// <returns>IHttpBehaviour</returns> public static OAuth1HttpBehaviour Create(OAuth1Settings oAuthSettings, IHttpBehaviour fromHttpBehaviour = null) { // Get a clone of a IHttpBehaviour (passed or current) var oauthHttpBehaviour = new OAuth1HttpBehaviour(fromHttpBehaviour); // Add a wrapper (delegate handler) which wraps all new HttpMessageHandlers oauthHttpBehaviour.ChainOnHttpMessageHandlerCreated(httpMessageHandler => new OAuth1HttpMessageHandler(oAuthSettings, oauthHttpBehaviour, httpMessageHandler)); return oauthHttpBehaviour; }
/// <summary> /// Create a specify OAuth IHttpBehaviour /// </summary> /// <param name="oAuthSettings">OAuthSettings</param> /// <param name="fromHttpBehaviour">IHttpBehaviour or null</param> /// <returns>IHttpBehaviour</returns> public static OAuth1HttpBehaviour Create(OAuth1Settings oAuthSettings, IHttpBehaviour fromHttpBehaviour = null) { // Get a clone of a IHttpBehaviour (passed or current) var oauthHttpBehaviour = new OAuth1HttpBehaviour(fromHttpBehaviour); // Add a wrapper (delegate handler) which wraps all new HttpMessageHandlers oauthHttpBehaviour.ChainOnHttpMessageHandlerCreated(httpMessageHandler => new OAuth1HttpMessageHandler(oAuthSettings, oauthHttpBehaviour, httpMessageHandler)); return(oauthHttpBehaviour); }
public FlickrDestination( IFlickrConfiguration flickrConfiguration, IFlickrLanguage flickrLanguage, INetworkConfiguration networkConfiguration, IResourceProvider resourceProvider, ICoreConfiguration coreConfiguration, IGreenshotLanguage greenshotLanguage, Func <CancellationTokenSource, Owned <PleaseWaitForm> > pleaseWaitFormFactory ) : base(coreConfiguration, greenshotLanguage) { _flickrConfiguration = flickrConfiguration; _flickrLanguage = flickrLanguage; _resourceProvider = resourceProvider; _pleaseWaitFormFactory = pleaseWaitFormFactory; _oAuthSettings = new OAuth1Settings { Token = flickrConfiguration, ClientId = flickrConfiguration.ClientId, ClientSecret = flickrConfiguration.ClientSecret, CloudServiceName = "Flickr", AuthorizeMode = AuthorizeModes.LocalhostServer, TokenUrl = FlickrOAuthUri.AppendSegments("request_token"), TokenMethod = HttpMethod.Post, AccessTokenUrl = FlickrOAuthUri.AppendSegments("access_token"), AccessTokenMethod = HttpMethod.Post, AuthorizationUri = FlickrOAuthUri.AppendSegments("authorize") .ExtendQuery(new Dictionary <string, string> { { OAuth1Parameters.Token.EnumValueOf(), "{RequestToken}" }, { OAuth1Parameters.Callback.EnumValueOf(), "{RedirectUrl}" } }), // Create a localhost redirect uri, prefer port 47336, but use the first free found RedirectUrl = new[] { 47336, 0 }.CreateLocalHostUri().AbsoluteUri, CheckVerifier = true }; _oAuthHttpBehaviour = OAuth1HttpBehaviourFactory.Create(_oAuthSettings); _oAuthHttpBehaviour.ValidateResponseContentType = false; // Use the default network settings _oAuthHttpBehaviour.HttpSettings = networkConfiguration; }
public PhotobucketDestination(IPhotobucketConfiguration photobucketConfiguration, IPhotobucketLanguage photobucketLanguage) { _photobucketConfiguration = photobucketConfiguration; _photobucketLanguage = photobucketLanguage; _oAuthSettings = new OAuth1Settings { Token = photobucketConfiguration, ClientId = photobucketConfiguration.ClientId, ClientSecret = photobucketConfiguration.ClientSecret, CloudServiceName = "Photobucket", EmbeddedBrowserWidth = 1010, EmbeddedBrowserHeight = 400, AuthorizeMode = AuthorizeModes.EmbeddedBrowser, TokenUrl = PhotobucketApiUri.AppendSegments("login", "request"), TokenMethod = HttpMethod.Post, AccessTokenUrl = PhotobucketApiUri.AppendSegments("login", "access"), AccessTokenMethod = HttpMethod.Post, AuthorizationUri = PhotobucketApiUri.AppendSegments("apilogin", "login") .ExtendQuery(new Dictionary <string, string> { { OAuth1Parameters.Token.EnumValueOf(), "{RequestToken}" }, { OAuth1Parameters.Callback.EnumValueOf(), "{RedirectUrl}" } }), RedirectUrl = "http://getgreenshot.org", CheckVerifier = false }; var oAuthHttpBehaviour = OAuth1HttpBehaviourFactory.Create(_oAuthSettings); // Store the leftover values oAuthHttpBehaviour.OnAccessTokenValues = values => { if (values != null && values.ContainsKey("subdomain")) { photobucketConfiguration.SubDomain = values["subdomain"]; } if (values != null && values.ContainsKey("username")) { photobucketConfiguration.Username = values["username"]; } }; oAuthHttpBehaviour.BeforeSend = httpRequestMessage => { if (photobucketConfiguration.SubDomain == null) { return; } var uriBuilder = new UriBuilder(httpRequestMessage.RequestUri) { Host = photobucketConfiguration.SubDomain }; httpRequestMessage.RequestUri = uriBuilder.Uri; }; // Reset the OAuth token if there is no subdomain, without this we need to request it again. if (photobucketConfiguration.SubDomain == null || photobucketConfiguration.Username == null) { photobucketConfiguration.OAuthToken = null; photobucketConfiguration.OAuthTokenSecret = null; } _oAuthHttpBehaviour = oAuthHttpBehaviour; }