Examples of OAuth1Operations


Examples of org.springframework.social.oauth1.OAuth1Operations

  }

  // 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

Examples of org.springframework.social.oauth1.OAuth1Operations

  @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

Examples of org.springframework.social.oauth1.OAuth1Operations

    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

Examples of org.springframework.social.oauth1.OAuth1Operations

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