protected override void PrepareHttpRequest(SocialHttpRequest request)
        {
            // Some validation
            if (String.IsNullOrWhiteSpace(Version))
            {
                throw new PropertyNotSetException("Version");
            }

            // Append the HTTP scheme and API version if not already specified.
            if (request.Url.StartsWith("/"))
            {
                request.Url = "https://graph.facebook.com/" + Version + request.Url;
            }

            // Append the access token to the query string if present in the client and not already
            // specified in the query string
            if (!request.QueryString.ContainsKey("access_token") && !String.IsNullOrWhiteSpace(AccessToken))
            {
                request.QueryString.Add("access_token", AccessToken);
            }

            // Append the locale to the query string if present in the client and not already
            // specified in the query string
            if (!request.QueryString.ContainsKey("locale") && !String.IsNullOrWhiteSpace(Locale))
            {
                request.QueryString.Add("locale", Locale);
            }
        }
 /// <summary>
 /// Virtual method that can be used for configuring a request.
 /// </summary>
 /// <param name="request">The instance of <see cref="SocialHttpRequest"/> representing the request.</param>
 protected override void PrepareHttpRequest(SocialHttpRequest request)
 {
     // Append the access token to the query string if present in the client and not already
     // specified in the query string
     if (!request.QueryString.ContainsKey("access_token") && !String.IsNullOrWhiteSpace(AccessToken))
     {
         request.QueryString.Add("access_token", AccessToken);
     }
 }
예제 #3
0
        /// <summary>
        /// Virtual method that can be used for configuring a request.
        /// </summary>
        /// <param name="request">The request.</param>
        protected override void PrepareHttpRequest(SocialHttpRequest request)
        {
            base.PrepareHttpRequest(request);

            // Append the scheme and host name if not already present
            if (request.Url.StartsWith("/"))
            {
                request.Url = "https://api.vimeo.com" + request.Url;
            }
        }
예제 #4
0
        /// <summary>
        /// Method responsible for updating the request with information specific to the BitBucket implementation.
        /// </summary>
        /// <param name="request">The request.</param>
        protected override void PrepareHttpRequest(SocialHttpRequest request)
        {
            // Append the protocol and domain if not already included in the URL
            if (request.Url.StartsWith("/"))
            {
                request.Url = "https://api.bitbucket.org" + request.Url;
            }

            // Call the base method for running all the OAuth logic
            base.PrepareHttpRequest(request);
        }
예제 #5
0
 /// <summary>
 /// Helper method for generating the OAuth signature for an instance of <see cref="SocialHttpRequest"/>.
 /// </summary>
 /// <param name="request">The instance of <see cref="SocialHttpRequest"/> the signature should be based on.</param>
 /// <returns>The generated OAuth signature.</returns>
 protected virtual string GenerateSignature(SocialHttpRequest request)
 {
     if (request == null)
     {
         throw new ArgumentNullException("request");
     }
     if (String.IsNullOrWhiteSpace(request.Url))
     {
         throw new PropertyNotSetException("request.Url");
     }
     return(GenerateSignature(request.Method, request.Url, request.QueryString, request.PostData));
 }
예제 #6
0
        /// <summary>
        /// Virtual method that can be used for configuring a request.
        /// </summary>
        /// <param name="request">The request.</param>
        protected override void PrepareHttpRequest(SocialHttpRequest request)
        {
            // Append the scheme and host name if not already present
            if (request.Url.StartsWith("/"))
            {
                request.Url = "https://api.vimeo.com" + request.Url;
            }

            // Append the access token if specified
            if (!String.IsNullOrWhiteSpace(AccessToken))
            {
                request.Authorization = "Bearer " + AccessToken;
            }
        }
예제 #7
0
        /// <summary>
        /// Virtual method that can be used for configuring a request.
        /// </summary>
        /// <param name="request">The instance of <see cref="SocialHttpRequest"/> representing the request.</param>
        protected override void PrepareHttpRequest(SocialHttpRequest request)
        {
            // Append the http scheme if not already specified
            if (request.Url.StartsWith("/"))
            {
                request.Url = "http://api.steampowered.com" + request.Url;
            }

            // Append the API key to the query string if present and not already specified in the query string
            if (!request.QueryString.Keys.Contains("key"))
            {
                request.QueryString.Add("key", ApiKey);
            }
        }
        /// <summary>
        /// Updates new HTTP requests with information specific to the Uptime Robot. If an <see cref="ApiKey"/> is
        /// specified, the value is appended to the HTTP post data to authenticate your requests.
        /// </summary>
        /// <param name="request">The request.</param>
        protected override void PrepareHttpRequest(SocialHttpRequest request)
        {
            if (request.PostData == null)
            {
                request.PostData = new SocialHttpPostData();
            }

            // Append the access token to the POST data
            if (!String.IsNullOrWhiteSpace(ApiKey))
            {
                request.PostData.Add("api_key", ApiKey);
            }

            request.PostData.Add("format", "json");
        }
예제 #9
0
        /// <summary>
        /// Adds the OAuth 1.0a authorization header to the request
        /// </summary>
        /// <param name="request"></param>
        protected override void PrepareHttpRequest(SocialHttpRequest request)
        {
            // Generate the signature
            string signature = GenerateSignature(request);

            // Generate the header
            string header = GenerateHeaderString(signature);

            // Add the authorization header
            request.Headers.Headers.Add("Authorization", header);

            // Make sure we reset the client (timestamp and nonce)
            if (AutoReset)
            {
                Reset();
            }
        }
        /// <summary>
        /// Virtual method that can be used for configuring a request.
        /// </summary>
        /// <param name="request">The instance of <see cref="SocialHttpRequest"/> representing the request.</param>
        protected override void PrepareHttpRequest(SocialHttpRequest request)
        {
            // Append the domain to the URL (if not already specified)
            if (request.Url.StartsWith("/"))
            {
                request.Url = "https://api.pinterest.com" + request.Url;
            }

            // Add an authorization header with the access token
            if (request.QueryString != null && !request.QueryString.ContainsKey("access_token") && !String.IsNullOrWhiteSpace(AccessToken))
            {
                request.QueryString.Add("access_token", AccessToken);

                // Apparently not all methods support a bearer token (getting the pins of a board)
                //request.Headers.Authorization = "Bearer " + AccessToken;
            }
        }
예제 #11
0
        /// <summary>
        /// Exchanges the specified <paramref name="authorizationCode"/> for a refresh token and an access token.
        /// </summary>
        /// <param name="authorizationCode">The authorization code received from the Sonos OAuth dialog.</param>
        /// <returns>An instance of <see cref="SonosTokenResponse"/> representing the response.</returns>
        /// <see>
        ///     <cref>https://developer.sonos.com/reference/authorization-api/create-token/</cref>
        /// </see>
        public SonosTokenResponse GetAccessTokenFromAuthorizationCode(string authorizationCode)
        {
            // Input validation
            if (String.IsNullOrWhiteSpace(authorizationCode))
            {
                throw new ArgumentNullException(nameof(authorizationCode));
            }
            if (String.IsNullOrWhiteSpace(ClientId))
            {
                throw new PropertyNotSetException(nameof(ClientId));
            }
            if (String.IsNullOrWhiteSpace(ClientSecret))
            {
                throw new PropertyNotSetException(nameof(ClientSecret));
            }
            if (String.IsNullOrWhiteSpace(RedirectUri))
            {
                throw new PropertyNotSetException(nameof(RedirectUri));
            }

            // Initialize the POST data
            SocialHttpPostData postData = new SocialHttpPostData {
                { "grant_type", "authorization_code" },
                { "code", authorizationCode },
                { "redirect_uri", RedirectUri }
            };

            // Initialize the request
            SocialHttpRequest request = new SocialHttpRequest {
                Method   = SocialHttpMethod.Post,
                Url      = "https://api.sonos.com/login/v3/oauth/access",
                PostData = postData
            };

            // Update the "Authorization" header
            request.Authorization = "Basic " + SecurityUtils.Base64Encode(ClientId + ":" + ClientSecret);

            // Make a request to the server
            SocialHttpResponse response = request.GetResponse();

            // Parse the JSON response
            return(SonosTokenResponse.ParseResponse(response));
        }
        /// <summary>
        /// Exchanges the specified <paramref name="authorizationCode"/> for a refresh token and an access token.
        /// </summary>
        /// <param name="authorizationCode">The authorization code received from the Spotify OAuth dialog.</param>
        /// <returns>An instance of <see cref="SpotifyTokenResponse"/> representing the response.</returns>
        /// <see>
        ///     <cref>https://developer.spotify.com/web-api/authorization-guide/</cref>
        /// </see>
        public SpotifyTokenResponse GetAccessTokenFromAuthorizationCode(string authorizationCode)
        {
            // Input validation
            if (String.IsNullOrWhiteSpace(authorizationCode))
            {
                throw new ArgumentNullException(nameof(authorizationCode));
            }
            if (String.IsNullOrWhiteSpace(ClientId))
            {
                throw new PropertyNotSetException(nameof(ClientId));
            }
            if (String.IsNullOrWhiteSpace(ClientSecret))
            {
                throw new PropertyNotSetException(nameof(ClientSecret));
            }
            if (String.IsNullOrWhiteSpace(RedirectUri))
            {
                throw new PropertyNotSetException(nameof(RedirectUri));
            }

            // Initialize the POST data
            IHttpPostData postData = new SocialHttpPostData();

            postData.Add("grant_type", "authorization_code");
            postData.Add("code", authorizationCode);
            postData.Add("redirect_uri", RedirectUri);
            postData.Add("client_id", ClientId);
            postData.Add("client_secret", ClientSecret);

            // Initialize the request
            SocialHttpRequest request = new SocialHttpRequest {
                Method   = SocialHttpMethod.Post,
                Url      = "https://accounts.spotify.com/api/token",
                PostData = postData
            };

            // Make a call to the server
            SocialHttpResponse response = request.GetResponse();

            // Parse the JSON response
            return(SpotifyTokenResponse.ParseResponse(response));
        }
예제 #13
0
        /// <summary>
        /// Exchanges the specified authorization code for an access token.
        /// </summary>
        /// <param name="authCode">The authorization code received from the Vimeo OAuth dialog.</param>
        /// <returns>An instance of <see cref="VimeoTokenResponse"/> representing the response.</returns>
        public VimeoTokenResponse GetAccessTokenFromAuthCode(string authCode)
        {
            // Some validation
            if (String.IsNullOrWhiteSpace(ClientId))
            {
                throw new PropertyNotSetException(nameof(ClientId));
            }
            if (String.IsNullOrWhiteSpace(ClientSecret))
            {
                throw new PropertyNotSetException(nameof(ClientSecret));
            }
            if (String.IsNullOrWhiteSpace(RedirectUri))
            {
                throw new PropertyNotSetException(nameof(RedirectUri));
            }
            if (String.IsNullOrWhiteSpace(authCode))
            {
                throw new ArgumentNullException(nameof(authCode));
            }

            // Initialize the POST data
            IHttpPostData data = new SocialHttpPostData();

            data.Add("grant_type", "authorization_code");
            data.Add("code", authCode);
            data.Add("redirect_uri", RedirectUri);

            // Initialize the request
            SocialHttpRequest request = new SocialHttpRequest {
                Method        = SocialHttpMethod.Post,
                Url           = "https://api.vimeo.com/oauth/access_token",
                PostData      = data,
                Authorization = "basic " + SecurityUtils.Base64Encode(ClientId + ":" + ClientSecret)
            };

            // Make the call to the API
            SocialHttpResponse response = request.GetResponse();

            // Parse the response
            return(VimeoTokenResponse.ParseResponse(response));
        }
예제 #14
0
        /// <summary>
        /// Virtual method that can be used for configuring a request.
        /// </summary>
        /// <param name="request">The instance of <see cref="SocialHttpRequest"/> representing the request.</param>
        protected override void PrepareHttpRequest(SocialHttpRequest request)
        {
            // Append either the access token or the client ID to the query string
            if (!String.IsNullOrWhiteSpace(AccessToken))
            {
                request.QueryString.Add("access_token", AccessToken);
            }
            else if (!String.IsNullOrWhiteSpace(ClientId))
            {
                request.QueryString.Add("client_id", ClientId);
            }

            if (SignedRequests)
            {
                // Get the endpoint from the URL
                string endpoint = request.Url.Replace("https://api.instagram.com/v1/", "/");

                // Append the signature to the request
                request.QueryString.Add("sig", GenerateSignature(endpoint, request.QueryString));
            }
        }