public void OAuthResponseBase_PropertiesMapped()
        {
            //Arrange
            var oauth2AuthHelper = new OAuth2AuthenticationHelper(GetOAuthCompleteUri());
            var list             = GetNavigationUris(1);

            var dictionary = new Dictionary <string, string>();

            dictionary.Add("appcp", "sharefile.com");
            dictionary.Add("apicp", "sf-api.com");
            dictionary.Add("randomKey", "randomValue");

            list.Add(GetOAuthCompleteUriWithParameters(dictionary));

            //Act
            bool           found    = false;
            IOAuthResponse response = null;

            foreach (var uri in list)
            {
                if (oauth2AuthHelper.IsComplete(uri, out response))
                {
                    found = true;
                    break;
                }
            }

            response.GetType().Should().Be(typeof(OAuthResponseBase));
            response.Properties.Should().NotBeNull();
            var oauthResponseBase = response as OAuthResponseBase;

            oauthResponseBase.ApiControlPlane.Should().Be("sf-api.com");
            oauthResponseBase.ApplicationControlPlane.Should().Be("sharefile.com");
            oauthResponseBase.Properties.Should().ContainKey("randomKey");
        }
        public bool GetOAuthResponse(bool includeCompleteUri, string key1, string key2, Type expectedType)
        {
            //Arrange
            var oauth2AuthHelper = new OAuth2AuthenticationHelper(GetOAuthCompleteUri());
            var list             = GetNavigationUris();

            var dictionary = new Dictionary <string, string>();

            dictionary.Add(key1, key1 + 123);
            dictionary.Add(key2, key2 + 123);

            if (includeCompleteUri)
            {
                list.Add(GetOAuthCompleteUriWithParameters(dictionary));
            }

            //Act
            bool           found    = false;
            IOAuthResponse response = null;

            foreach (var uri in list)
            {
                if (oauth2AuthHelper.IsComplete(uri, out response))
                {
                    found = true;
                    break;
                }
            }

            return(found && (response != null && response.GetType() == expectedType));
        }
Exemplo n.º 3
0
        private static void OAuth()
        {
            string secret = "YOUR_APPLICATION_SECRET";

            string code = "YOUR_CODE";             // received @ approval uri

            IOAuthResponse response = oauth.RequestAccessToken(secret, code);

            Console.WriteLine(response.AccessToken);
        }
        public bool IsComplete(Uri navigationUri, out IOAuthResponse response)
        {
            response = null;
            if (navigationUri.ToString().StartsWith(_completionUrl))
            {
                var queryString = navigationUri.Query.ToQueryStringCollection();
                if (queryString == null) return false;

                response = queryString.ToOAuthResponse();
                return true;
            }

            return false;
        }
        private void HandleOAuthResponse(IOAuthResponse response)
        {
            var error = response as OAuthError;
            if (error != null)
            {
                MessageBox.Show(error.ErrorDescription, "Authentication Failed", MessageBoxButtons.OK);
                return;
            }

            var authenticationCode = response as OAuthAuthorizationCode;
            if (authenticationCode != null)
            {
                ExchangeAuthorizationCode(authenticationCode);
            }
        }
Exemplo n.º 6
0
        private void HandleOAuthResponse(IOAuthResponse response)
        {
            var error = response as OAuthError;

            if (error != null)
            {
                MessageBox.Show(error.ErrorDescription, "Authentication Failed", MessageBoxButtons.OK);
                return;
            }

            var authenticationCode = response as OAuthAuthorizationCode;

            if (authenticationCode != null)
            {
                ExchangeAuthorizationCode(authenticationCode);
            }
        }
        public bool IsComplete(Uri navigationUri, out IOAuthResponse response)
        {
            response = null;
            if (navigationUri.ToString().StartsWith(_completionUrl))
            {
                var queryString = navigationUri.Query.ToQueryStringCollection();
                if (queryString == null)
                {
                    return(false);
                }

                response = queryString.ToOAuthResponse();
                return(true);
            }

            return(false);
        }