Package org.springframework.social.oauth1

Examples of org.springframework.social.oauth1.OAuth1Template


   * @param request the current web request
   * @return a new connection to the service provider
   */
  public Connection<?> completeConnection(OAuth1ConnectionFactory<?> connectionFactory, NativeWebRequest request) {
    String verifier = request.getParameter("oauth_verifier");
    AuthorizedRequestToken requestToken = new AuthorizedRequestToken(extractCachedRequestToken(request), verifier);
    OAuthToken accessToken = connectionFactory.getOAuthOperations().exchangeForAccessToken(requestToken, null);
    return connectionFactory.createConnection(accessToken);
  }
View Full Code Here


      final String verifier) {
    return Matchers.argThat(new ArgumentMatcher<AuthorizedRequestToken>() {

      public boolean matches(Object item) {
        if (item instanceof AuthorizedRequestToken) {
          AuthorizedRequestToken token = (AuthorizedRequestToken) item;
          return eq(value, token.getValue()) && eq(secret, token.getSecret())
              && eq(verifier, token.getVerifier());
        }
        return false;
      }

    });
View Full Code Here

      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

  }

  // internal helpers
 
  private String buildOAuth1Url(OAuth1ConnectionFactory<?> connectionFactory, NativeWebRequest request, MultiValueMap<String, String> additionalParameters) {
    OAuth1Operations oauthOperations = connectionFactory.getOAuthOperations();
    MultiValueMap<String, String> requestParameters = getRequestParameters(request);
    OAuth1Parameters parameters = getOAuth1Parameters(request, additionalParameters);
    parameters.putAll(requestParameters);
    if (oauthOperations.getVersion() == OAuth1Version.CORE_10) {
      parameters.setCallbackUrl(callbackUrl(request));
    }
    OAuthToken requestToken = fetchRequestToken(request, requestParameters, oauthOperations);
    sessionStrategy.setAttribute(request, OAUTH_TOKEN_ATTRIBUTE, requestToken);
    return buildOAuth1Url(oauthOperations, requestToken.getValue(), parameters);
View Full Code Here

  @Test
  public void test() throws Exception {
    @SuppressWarnings("unchecked")
    final OAuth1ConnectionFactory<Object> factory = mock(OAuth1ConnectionFactory.class);
    final OAuth1Operations operations = mock(OAuth1Operations.class);
    final String serverName = "example.com";
    final String serviceUrl = "http://twitter.com/auth";
    final OAuthToken oAuthToken = new OAuthToken("my_token", "my_secret");
    final String verifier = "my_verifier";
    final Connection<Object> connection = DummyConnection.dummy("provider", "user");
   
    final OAuth1AuthenticationService<Object> authSvc = new OAuth1AuthenticationService<Object>(factory);
    authSvc.getReturnToUrlParameters().add("param");
    authSvc.afterPropertiesSet();
   
    final MockServletContext context = new MockServletContext();
    final MockHttpSession session = new MockHttpSession(context);
   
    // mock definitions
    when(factory.getProviderId()).thenReturn(connection.getKey().getProviderId());
    when(factory.getOAuthOperations()).thenReturn(operations);
    when(factory.createConnection(ArgMatchers.oAuthToken(oAuthToken))).thenReturn(connection);
   
    when(operations.getVersion()).thenReturn(OAuth1Version.CORE_10_REVISION_A);
    when(operations.fetchRequestToken("http://"+serverName+"/auth/foo?param=param_value", null)).thenReturn(oAuthToken);
    when(operations.exchangeForAccessToken(ArgMatchers.authorizedRequestToken(oAuthToken, verifier), Matchers.same((MultiValueMap<String, String>) null))).thenReturn(oAuthToken);
    when(operations.buildAuthenticateUrl(oAuthToken.getValue(), OAuth1Parameters.NONE)).thenReturn(serviceUrl + "?oauth_token=" + oAuthToken.getValue());
   
    // first phase
    MockHttpServletRequest request = new MockHttpServletRequest(context, "GET", "/auth/foo");
    request.setServerName(serverName);
    request.setSession(session);
View Full Code Here

    public TestOAuth1ServiceProvider(OAuth1Version version) {
      this.version = version;
    }
   
    public OAuth1Operations getOAuthOperations() {
      return new OAuth1Operations() {
        public OAuth1Version getVersion() {
          return version;
        }

        public OAuthToken fetchRequestToken(String callbackUrl, MultiValueMap<String, String> additionalParameters) {
View Full Code Here

     * OAuth Authentication flow: See http://dev.twitter.com/pages/auth
     */
    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");
View Full Code Here

  // internal helpers
 
  private String buildOAuth1Url(OAuth1ConnectionFactory<?> connectionFactory, NativeWebRequest request, MultiValueMap<String, String> additionalParameters) {
    OAuth1Operations oauthOperations = connectionFactory.getOAuthOperations();
    MultiValueMap<String, String> requestParameters = getRequestParameters(request);
    OAuth1Parameters parameters = getOAuth1Parameters(request, additionalParameters);
    parameters.putAll(requestParameters);
    if (oauthOperations.getVersion() == OAuth1Version.CORE_10) {
      parameters.setCallbackUrl(callbackUrl(request));
    }
    OAuthToken requestToken = fetchRequestToken(request, requestParameters, oauthOperations);
    sessionStrategy.setAttribute(request, OAUTH_TOKEN_ATTRIBUTE, requestToken);
    return buildOAuth1Url(oauthOperations, requestToken.getValue(), parameters);
  }
View Full Code Here

    sessionStrategy.setAttribute(request, OAUTH_TOKEN_ATTRIBUTE, requestToken);
    return buildOAuth1Url(oauthOperations, requestToken.getValue(), parameters);
  }

  private OAuth1Parameters getOAuth1Parameters(NativeWebRequest request, MultiValueMap<String, String> additionalParameters) {
    OAuth1Parameters parameters = new OAuth1Parameters(additionalParameters);
    parameters.putAll(getRequestParameters(request));
    return parameters;
  }
View Full Code Here

      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 {
View Full Code Here

TOP

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

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.