Package org.springframework.social.oauth1

Examples of org.springframework.social.oauth1.OAuth1RequestInterceptorTest


  @Override
  public OAuthToken exchangeForAccessToken(AuthorizedRequestToken requestToken, MultiValueMap<String, String> additionalParameters) {
    if (behavior == THROW_EXCEPTION) {
      throw new HttpClientErrorException(BAD_REQUEST);
    }
    return new OAuthToken("accessToken", "accessTokenSecret");
  }
View Full Code Here


        public OAuth1Version getVersion() {
          return version;
        }

        public OAuthToken fetchRequestToken(String callbackUrl, MultiValueMap<String, String> additionalParameters) {
          return new OAuthToken("requestTokenValue", "requestTokenSecret");
        }

        public String buildAuthorizeUrl(String requestToken, OAuth1Parameters params) {
          String additionalParametersQuery = additionalParametersQuery(params, false);
          return "https://serviceprovider.com/oauth/authorize" + additionalParametersQuery;
        }

        public String buildAuthenticateUrl(String requestToken, OAuth1Parameters params) {
          String additionalParametersQuery = additionalParametersQuery(params, false);
          return "https://serviceprovider.com/oauth/authenticate" + additionalParametersQuery;
        }

        public OAuthToken exchangeForAccessToken(AuthorizedRequestToken requestToken, MultiValueMap<String, String> additionalParameters) {
          assertEquals("requestToken", requestToken.getValue());
          assertEquals("requestTokenSecret", requestToken.getSecret());
          assertNull(additionalParameters);
          return new OAuthToken("accessToken", "accessTokenSecret");
        }               
      };
    }
View Full Code Here

    connectController.setConnectInterceptors(interceptors);
    connectController.afterPropertiesSet();
    MockMvc mockMvc = standaloneSetup(connectController).build();
    mockMvc.perform(post("/connect/oauth1Provider"))
      .andExpect(redirectedUrl("https://someprovider.com/oauth/authorize?oauth_token=requestToken"))
      .andExpect(request().sessionAttribute("oauthToken", samePropertyValuesAs(new OAuthToken("requestToken", "requestTokenSecret"))));
    // Check for preConnect() only. The postConnect() won't be invoked until after callback
    TestConnectInterceptor<?> textInterceptor1 = (TestConnectInterceptor<?>)(interceptors.get(0));
    assertTrue(textInterceptor1.preConnectInvoked);
    assertEquals("oauth1Provider", textInterceptor1.connectionFactory.getProviderId());     
    assertFalse(((TestConnectInterceptor<?>)(interceptors.get(1))).preConnectInvoked);
View Full Code Here

    connectController.setConnectInterceptors(interceptors);
    connectController.afterPropertiesSet();
    MockMvc mockMvc = standaloneSetup(connectController).build();
    assertEquals(0, connectionRepository.findConnections("oauth2Provider").size());   
    mockMvc.perform(get("/connect/oauth1Provider")
            .sessionAttr("oauthToken", new OAuthToken("requestToken", "requestTokenSecret"))
            .param("oauth_token", "requestToken")
            .param("oauth_verifier", "verifier"))
      .andExpect(redirectedUrl("/connect/oauth1Provider"));
    List<Connection<?>> connections = connectionRepository.findConnections("oauth1Provider");
    assertEquals(1, connections.size());
View Full Code Here

    connectionFactoryLocator.addConnectionFactory(connectionFactory);
    StubConnectionRepository connectionRepository = new StubConnectionRepository();
    MockMvc mockMvc = standaloneSetup(new ConnectController(connectionFactoryLocator, connectionRepository)).build();
    assertEquals(0, connectionRepository.findConnections("oauth2Provider").size());   
    mockMvc.perform(get("/connect/oauth1Provider")
            .sessionAttr("oauthToken", new OAuthToken("requestToken", "requestTokenSecret"))
            .param("oauth_token", "requestToken")
            .param("oauth_verifier", "verifier"))
      .andExpect(redirectedUrl("/connect/oauth1Provider"))
      .andExpect(request().sessionAttribute("social_provider_error", notNullValue()));
    assertEquals(0, connectionRepository.findConnections("oauth2Provider").size());   
View Full Code Here

    String verifier = request.getParameter("oauth_verifier");
    if (!StringUtils.hasText(verifier)) {
      // First phase: get a request token
      OAuth1Operations ops = getConnectionFactory().getOAuthOperations();
      String returnToUrl = buildReturnToUrl(request);
      OAuthToken requestToken = ops.fetchRequestToken(returnToUrl, null);
      request.getSession().setAttribute(OAUTH_TOKEN_ATTRIBUTE, requestToken);

      // Redirect to the service provider for authorization
      OAuth1Parameters params;
      if (ops.getVersion() == OAuth1Version.CORE_10) {
        params = new OAuth1Parameters();
        params.setCallbackUrl(returnToUrl);
      } else {
        params = OAuth1Parameters.NONE;
      }     
      throw new SocialAuthenticationRedirectException(ops.buildAuthenticateUrl(requestToken.getValue(), params));
    } else {
      // Second phase: request an access token
      OAuthToken requestToken = extractCachedRequestToken(request);
      if (requestToken == null) {
        logger.warn("requestToken unavailable for oauth_verifier");
        return null;
      }
      OAuthToken accessToken = getConnectionFactory().getOAuthOperations().exchangeForAccessToken(new AuthorizedRequestToken(requestToken, verifier), null);
      // TODO avoid API call if possible (auth using token would be fine)
            Connection<S> connection = getConnectionFactory().createConnection(accessToken);
            return new SocialAuthenticationToken(connection, null);
    }
  }
View Full Code Here

    return sb.toString();
  }

  private OAuthToken extractCachedRequestToken(HttpServletRequest request) {
    OAuthToken requestToken = (OAuthToken) request.getSession().getAttribute(OAUTH_TOKEN_ATTRIBUTE);
    request.getSession().removeAttribute(OAUTH_TOKEN_ATTRIBUTE);
    return requestToken;
  }
View Full Code Here

  @Test
  public void completeConnection_OAuth1() {
    ConnectSupport support = new ConnectSupport();
    MockHttpServletRequest mockRequest = new PortAwareMockHttpServletRequest();
    mockRequest.addParameter("oauth_verifier", "verifier");
    mockRequest.getSession().setAttribute("oauthToken", new OAuthToken("requestToken", "requestTokenSecret"));
    mockRequest.setScheme("http");
    mockRequest.setServerName("somesite.com");
    mockRequest.setRequestURI("/connect/someprovider");
    ServletWebRequest request = new ServletWebRequest(mockRequest);
    Connection<?> connection = support.completeConnection(new TestOAuth1ConnectionFactory(OAuth1Version.CORE_10_REVISION_A), request);
View Full Code Here

  public OAuth1Version getVersion() {
    return OAuth1Version.CORE_10_REVISION_A;
  }
 
  public OAuthToken fetchRequestToken(String callbackUrl, MultiValueMap<String, String> additionalParameters) {
    return new OAuthToken("12345", "23456");
  }
View Full Code Here

  public String buildAuthenticateUrl(String requestToken, OAuth1Parameters parameters) {
    return "http://springsource.org/oauth/authenticate?request_token=" + requestToken;
  }

  public OAuthToken exchangeForAccessToken(AuthorizedRequestToken requestToken, MultiValueMap<String, String> additionalParameters) {
    return new OAuthToken("34567", "45678");
  }
View Full Code Here

TOP

Related Classes of org.springframework.social.oauth1.OAuth1RequestInterceptorTest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.