Ejemplo n.º 1
0
        public void ItCanReEstablishSessionStateFromAuthorizationRequest()
        {
            // Arrange
            Request protectedResourceRequest = Session.Bind(OAuth2TestConstants.ProtectedResourcePath);

            Session.OAuth2_Configure(GetSettings())
            .OAuth2_GetAuthorizationRequestUrl();

            OAuth2SessionState state = Session.OAuth2_GetState();

            // Act
            ISession newSession = TestService.NewSession();

            newSession.OAuth2_RestoreState(state);

            // Assert ... we don't have a real endpoint for this, so simulate the redirect URL
            string failUrl    = "http://localhost?code=xyz&state=123";
            string successUrl = "http://localhost?code=xyz&state=" + state.AuthorizationState;

            string code1 = newSession.OAuth2_GetAuthorizationCodeFromRedirectUrl(failUrl);
            string code2 = newSession.OAuth2_GetAuthorizationCodeFromRedirectUrl(successUrl);

            Assert.IsNull(code1);
            Assert.AreEqual("xyz", code2);
        }
Ejemplo n.º 2
0
        public void WhenRequestingAuthorizationCodeItSavesState()
        {
            // Act
            Uri authUrl =
                Session.OAuth2_Configure(GetSettings())
                .OAuth2_GetAuthorizationRequestUrl();

            OAuth2SessionState state = Session.OAuth2_GetState();

            // Assert
            Assert.IsNotNull(state);
            Assert.IsNotNull(state.AuthorizationState);
            Assert.Greater(state.AuthorizationState.Length, 8);
        }
Ejemplo n.º 3
0
        public void CanRestoreSessionStateWithAccessToken()
        {
            // Arrange
            Session.OAuth2_Configure(GetSettings())
            .OAuth2_GetAccessTokenUsingOwnerUsernamePassword(OAuth2TestConstants.Username, OAuth2TestConstants.UserPassword);

            OAuth2SessionState state = Session.OAuth2_GetState();

            // Act
            ISession newSession = TestService.NewSession();

            Request protectedResourceRequest = newSession.OAuth2_RestoreState(state).Bind(OAuth2TestConstants.ProtectedResourcePath);

            using (var response = protectedResourceRequest.AcceptJson().Get <ProtectedResource>())
            {
                ProtectedResource r = response.Body;

                // Assert
                Assert.IsNotNull(r);
                Assert.AreEqual("Got it", r.Title);
            }
        }