Example #1
0
        public string BuildAuthorizeUrl(OAuth2AuthorizationFlow oAuth2AuthorizationFlow, string redirectUri, string state = null)
        {
            if (string.IsNullOrWhiteSpace(redirectUri))
            {
                throw new ArgumentNullException("redirectUri");
            }
            RestRequest request = _requestHelper.BuildOAuth2AuthorizeUrl(oAuth2AuthorizationFlow, _apiKey, redirectUri, state);

            return(_restClientMainServer.BuildUri(request).ToString());
        }
Example #2
0
        private void TestOAuth2AuthorizationUrl(OAuth2AuthorizationFlow oAuth2AuthorizationFlow, string expectedResponseType, string state = null)
        {
            const string expectedFormat = "https://api.dropbox.com/1/oauth2/authorize?response_type={0}&client_id={1}&redirect_uri=http://example.com{2}";
            var          stateQuery     = string.IsNullOrWhiteSpace(state) ? string.Empty : string.Format("&state={0}", state);
            var          expected       = string.Format(expectedFormat, expectedResponseType, TestVariables.ApiKey, stateQuery);
            var          actual         = _client.BuildAuthorizeUrl(oAuth2AuthorizationFlow, "http://example.com", state);

            Assert.IsNotNull(actual);
            Assert.AreEqual(expected, actual);
        }
Example #3
0
 /// <summary>
 /// This is the first step the OAuth 2.0 authorization flow. This isn't an API call—it's the web page that lets the user sign in to Dropbox and authorize your app. The user must be redirected to the page over HTTPS and it should be presented to the user through their web browser. After the user decides whether or not to authorize your app, they will be redirected to the URL specified by redirect_uri.
 /// </summary>
 /// <param name="oAuth2AuthorizationFlow">The type of authorization flow to use.  See AuthorizationFlow documentation for descriptions of each.</param>
 /// <param name="consumerKey"></param>
 /// <param name="redirectUri">Where to redirect the user after authorization has completed. This must be the exact URI registered in the app console, though localhost and 127.0.0.1 are always accepted. A redirect URI is required for a token flow, but optional for code. If the redirect URI is omitted, the code will be presented directly to the user and they will be invited to enter the information in your app.</param>
 /// <param name="state">Arbitrary data that will be passed back to your redirect URI. This parameter can be used to track a user through the authorization flow.</param>
 /// <returns>A URL to which you should redirect the user.  Because /oauth2/authorize is a website, there is no direct return value. However, after the user authorizes your app, they will be sent to your redirect URI. The type of response varies based on the response_type.</returns>
 public RestRequest BuildOAuth2AuthorizeUrl(OAuth2AuthorizationFlow oAuth2AuthorizationFlow, string consumerKey, string redirectUri, string state = null)
 {
     var request = new RestRequest("{version}/oauth2/authorize", Method.GET);
     request.AddParameter("version", _version, ParameterType.UrlSegment);
     request.AddParameter("response_type", Enum.GetName(typeof(OAuth2AuthorizationFlow), oAuth2AuthorizationFlow).ToLower());
     request.AddParameter("client_id", consumerKey);
     request.AddParameter("redirect_uri", redirectUri);
     if (!string.IsNullOrWhiteSpace(state))
     {
         request.AddParameter("state", state);
     }
     return request;
 }
Example #4
0
        /// <summary>
        /// This is the first step the OAuth 2.0 authorization flow. This isn't an API call—it's the web page that lets the user sign in to Dropbox and authorize your app. The user must be redirected to the page over HTTPS and it should be presented to the user through their web browser. After the user decides whether or not to authorize your app, they will be redirected to the URL specified by redirect_uri.
        /// </summary>
        /// <param name="oAuth2AuthorizationFlow">The type of authorization flow to use.  See AuthorizationFlow documentation for descriptions of each.</param>
        /// <param name="consumerKey"></param>
        /// <param name="redirectUri">Where to redirect the user after authorization has completed. This must be the exact URI registered in the app console, though localhost and 127.0.0.1 are always accepted. A redirect URI is required for a token flow, but optional for code. If the redirect URI is omitted, the code will be presented directly to the user and they will be invited to enter the information in your app.</param>
        /// <param name="state">Arbitrary data that will be passed back to your redirect URI. This parameter can be used to track a user through the authorization flow.</param>
        /// <returns>A URL to which you should redirect the user.  Because /oauth2/authorize is a website, there is no direct return value. However, after the user authorizes your app, they will be sent to your redirect URI. The type of response varies based on the response_type.</returns>
        public RestRequest BuildOAuth2AuthorizeUrl(OAuth2AuthorizationFlow oAuth2AuthorizationFlow, string consumerKey, string redirectUri, string state = null)
        {
            var request = new RestRequest("{version}/oauth2/authorize", Method.GET);

            request.AddParameter("version", _version, ParameterType.UrlSegment);
            request.AddParameter("response_type", Enum.GetName(typeof(OAuth2AuthorizationFlow), oAuth2AuthorizationFlow).ToLower());
            request.AddParameter("client_id", consumerKey);
            request.AddParameter("redirect_uri", redirectUri);
            if (!string.IsNullOrWhiteSpace(state))
            {
                request.AddParameter("state", state);
            }
            return(request);
        }
        /// <summary>
        /// This starts the OAuth 2.0 authorization flow. This isn't an API call—it's the web page that lets the user sign in to Dropbox and authorize your app. The user must be redirected to the page over HTTPS and it should be presented to the user through their web browser. After the user decides whether or not to authorize your app, they will be redirected to the URL specified by the 'redirectUri'.
        /// </summary>
        /// <param name="oAuth2AuthorizationFlow">The type of authorization flow to use.  See the OAuth2AuthorizationFlow enum documentation for more information.</param>
        /// <param name="redirectUri">Where to redirect the user after authorization has completed. This must be the exact URI registered in the app console (https://www.dropbox.com/developers/apps), though localhost and 127.0.0.1 are always accepted. A redirect URI is required for a token flow, but optional for code. If the redirect URI is omitted, the code will be presented directly to the user and they will be invited to enter the information in your app.</param>
        /// <param name="state">Arbitrary data that will be passed back to your redirect URI. This parameter can be used to track a user through the authorization flow in order to prevent cross-site request forgery (CRSF) attacks.</param>
        /// <returns>A URL to which your app should redirect the user for authorization.  After the user authorizes your app, they will be sent to your redirect URI. The type of response varies based on the 'oauth2AuthorizationFlow' argument.  .</returns>
        public string BuildAuthorizeUrl(OAuth2AuthorizationFlow oAuth2AuthorizationFlow, string redirectUri, string state = null)
        {
            if (string.IsNullOrWhiteSpace(redirectUri))
            {
                throw new ArgumentNullException("redirectUri");
            }

            var queryParams = new List <KeyValuePair <string, string> > {
                new KeyValuePair <string, string>("response_type", Enum.GetName(typeof(OAuth2AuthorizationFlow), oAuth2AuthorizationFlow).ToLower( )),
                new KeyValuePair <string, string>("client_id", this._apiKey),
                new KeyValuePair <string, string>("redirect_uri", redirectUri)
            };

            if (!string.IsNullOrWhiteSpace(state))
            {
                queryParams.Add(new KeyValuePair <string, string>("state", state));
            }

            return(string.Format("{0}/{1}/oauth2/authorize{2}", ApiBaseUrl, Version,
                                 queryParams.ToQueryString( )
                                 ));
        }
Example #6
0
        private void TestOAuth2AuthorizationUrl(OAuth2AuthorizationFlow oAuth2AuthorizationFlow, string expectedResponseType, string state = null)
        {
            var actual = this._client.BuildAuthorizeUrl(oAuth2AuthorizationFlow, "http://example.com", state);

            Assert.IsNotNull(actual);


            var queryParams = new List <KeyValuePair <string, string> > {
                new KeyValuePair <string, string>("response_type", expectedResponseType),
                new KeyValuePair <string, string>("client_id", TestVariables.DropBoxApiKey),
                new KeyValuePair <string, string>("redirect_uri", "http://example.com")
            };

            if (!string.IsNullOrWhiteSpace(state))
            {
                queryParams.Add(new KeyValuePair <string, string>("state", state));
            }
            const string expectedFormat = "https://api.dropbox.com/1/oauth2/authorize";
            var          expected       = expectedFormat + queryParams.ToQueryString( );

            Assert.AreEqual(expected, actual);
        }
Example #7
0
 private void TestOAuth2AuthorizationUrl(OAuth2AuthorizationFlow oAuth2AuthorizationFlow, string expectedResponseType, string state = null)
 {
     const string expectedFormat = "https://api.dropbox.com/1/oauth2/authorize?response_type={0}&client_id={1}&redirect_uri=http://example.com{2}";
     var stateQuery = string.IsNullOrWhiteSpace(state) ? string.Empty : string.Format("&state={0}", state);
     var expected = string.Format(expectedFormat, expectedResponseType, TestVariables.ApiKey, stateQuery);
     var actual = _client.BuildAuthorizeUrl(oAuth2AuthorizationFlow, "http://example.com", state);
     Assert.IsNotNull(actual);
     Assert.AreEqual(expected, actual);
 }