Examples of OauthToken


Examples of org.springframework.social.oauth1.OAuthToken

    ProviderSignInController providerSignInController = new ProviderSignInController(connectionFactoryLocator, usersConnectionRepository, null);
    providerSignInController.afterPropertiesSet();
    MockMvc mockMvc = standaloneSetup(providerSignInController).build();
    mockMvc.perform(post("/signin/oauth1Provider"))
      .andExpect(redirectedUrl("https://someprovider.com/oauth/authorize?oauth_token=requestToken"))
      .andExpect(request().sessionAttribute("oauthToken", samePropertyValuesAs(new OAuthToken("requestToken", "requestTokenSecret"))));
  }
View Full Code Here

Examples of org.springframework.social.oauth1.OAuthToken

   * @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

Examples of org.springframework.social.oauth1.OAuthToken

    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

Examples of org.springframework.social.oauth1.OAuthToken

      return oauthOperations.buildAuthorizeUrl(requestToken, parameters);
    }
  }

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

Examples of org.springframework.social.oauth1.OAuthToken

  public static OAuthToken oAuthToken(final String value, final String secret) {
    return Matchers.argThat(new ArgumentMatcher<OAuthToken>() {

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

    });
View Full Code Here

Examples of org.springframework.social.oauth1.OAuthToken

    @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);
    request.addParameter("param", "param_value");
    MockHttpServletResponse response = new MockHttpServletResponse();
   
    try {
      SocialAuthenticationToken token = authSvc.getAuthToken(request, response);
      fail("redirect expected, was token " + token);
    } catch (SocialAuthenticationRedirectException e) {
      // expect redirect to service url including token
      assertEquals(serviceUrl + "?oauth_token=" + oAuthToken.getValue(), e.getRedirectUrl());
    }
   
    // second phase
    request = new MockHttpServletRequest(context, "GET", "/auth/foo");
    request.setServerName(serverName);
View Full Code Here

Examples of org.springframework.social.oauth1.OAuthToken

   
    if (behavior == THROW_EXCEPTION) {
      throw new HttpClientErrorException(BAD_REQUEST);
    }
   
    return new OAuthToken("requestToken", "requestTokenSecret");
  }
View Full Code Here

Examples of org.springframework.social.oauth1.OAuthToken

  @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

Examples of org.springframework.social.oauth1.OAuthToken

        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

Examples of org.springframework.social.oauth1.OAuthToken

    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
TOP
Copyright © 2018 www.massapi.com. 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.