Ejemplo n.º 1
0
        public async Task RequestCredentials_ParsesTheTwitterResultAndReturnsCredentials()
        {
            // Arrange
            var controller     = CreateAuthController();
            var request        = A.Fake <ITwitterRequest>();
            var expectedResult = A.Fake <ITwitterResult>();
            var parameters     = new RequestCredentialsParameters("verifier_code", new AuthenticationRequest
            {
                ConsumerKey    = "consumer_key",
                ConsumerSecret = "consumer_secret"
            });

            var response = "oauth_token=access_token&oauth_token_secret=access_secret";

            A.CallTo(() => _fakeAuthQueryExecutor.RequestCredentials(parameters, request)).Returns(expectedResult);
            A.CallTo(() => expectedResult.RawResult).Returns(response);

            // Act
            var result = await controller.RequestCredentials(parameters, request);

            // Assert
            Assert.Equal(result.DataTransferObject.AccessToken, $"access_token");
            Assert.Equal(result.DataTransferObject.AccessTokenSecret, $"access_secret");
            Assert.Equal(result.DataTransferObject.ConsumerKey, $"consumer_key");
            Assert.Equal(result.DataTransferObject.ConsumerSecret, $"consumer_secret");
        }
Ejemplo n.º 2
0
        public async Task <ITwitterResult <ITwitterCredentials> > RequestCredentials(IRequestCredentialsParameters parameters, ITwitterRequest request)
        {
            var twitterResult = await _authQueryExecutor.RequestCredentials(parameters, request).ConfigureAwait(false);

            var oAuthToken       = twitterResult.RawResult.GetURLParameter("oauth_token");
            var oAuthTokenSecret = twitterResult.RawResult.GetURLParameter("oauth_token_secret");

            if (oAuthToken == null || oAuthTokenSecret == null)
            {
                throw new TwitterAuthException(twitterResult, "Invalid authentication response");
            }

            var credentials = new TwitterCredentials(
                parameters.AuthRequest.ConsumerKey,
                parameters.AuthRequest.ConsumerSecret,
                oAuthToken,
                oAuthTokenSecret);

            return(new TwitterResult <ITwitterCredentials>
            {
                Request = twitterResult.Request,
                Response = twitterResult.Response,
                DataTransferObject = credentials
            });
        }