コード例 #1
0
        public void ExtractAuthorizationStateFromUri_Error()
        {
            // ARRANGE
            Mock.Arrange(() => Arg.IsAny <Uri>().MustNotNull(Arg.AnyString)).DoNothing().Occurs(1);
            Mock.Arrange(() => OAuthErrorParser.ParseError(Arg.AnyString)).Throws(new DracoonApiException());
            Uri param = new Uri("https://dracoon.team/oauth/callback?error=someOccuredError");

            // ACT - ASSERT
            Assert.Throws <DracoonApiException>(() => OAuthHelper.ExtractAuthorizationStateFromUri(param));
            Mock.Assert(() => Arg.IsAny <Uri>().MustNotNull(Arg.AnyString));
        }
コード例 #2
0
        public void ExtractAuthorizationStateFromUri()
        {
            // ARRANGE
            string expectedCode  = "code1";
            string expectedState = "state1";

            Mock.Arrange(() => Arg.IsAny <Uri>().MustNotNull(Arg.AnyString)).DoNothing().Occurs(1);
            Uri param = new Uri("https://dracoon.team/oauth/callback?code=" + expectedCode + "&state=" + expectedState);

            // ACT
            string actual = OAuthHelper.ExtractAuthorizationStateFromUri(param);

            // ASSERT
            Assert.Equal(expectedState, actual);
            Mock.Assert(() => Arg.IsAny <Uri>().MustNotNull(Arg.AnyString));
        }
コード例 #3
0
        private static string AuthorizeClient()
        {
            string state = GenerateRandomBase64(32);

            // Create authorization uri
            Uri authUrl = OAuthHelper.CreateAuthorizationUrl(SERVER_URI, CLIENT_ID, state);

            // Open authorization URL in user's browser and wait for callback
            Uri loginResultUri = Login(authUrl).Result;

            // Extract the state and code from callback uri
            string callbackState = OAuthHelper.ExtractAuthorizationStateFromUri(loginResultUri);
            string callbackCode  = OAuthHelper.ExtractAuthorizationCodeFromUri(loginResultUri);

            // Check state
            if (!state.Equals(callbackState))
            {
                throw new Exception("Received OAuth state is not the same as expected!");
            }
            return(callbackCode);
        }