Examples of OAuthClient


Examples of org.apache.oltu.oauth2.client.OAuthClient

    }

    private String extractUsername(String code) {

        try {
            OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

            OAuthClientRequest accessTokenRequest = OAuthClientRequest
                    .tokenLocation(accessTokenUrl)
                    .setGrantType(GrantType.AUTHORIZATION_CODE)
                    .setClientId(clientId)
                    .setClientSecret(clientSecret)
                    .setCode(code)
                    .setRedirectURI(redirectUrl)
                    .buildQueryMessage();

            OAuthAccessTokenResponse oAuthResponse = oAuthClient.accessToken(accessTokenRequest, OAuth.HttpMethod.POST);

            String accessToken = oAuthResponse.getAccessToken();
            Long expiresIn = oAuthResponse.getExpiresIn();

            OAuthClientRequest userInfoRequest = new OAuthBearerClientRequest(userInfoUrl)
                    .setAccessToken(accessToken).buildQueryMessage();

            OAuthResourceResponse resourceResponse = oAuthClient.resource(userInfoRequest, OAuth.HttpMethod.GET, OAuthResourceResponse.class);
            String username = resourceResponse.getBody();
            return username;
        } catch (Exception e) {
            e.printStackTrace();
            throw new OAuth2AuthenticationException(e);
View Full Code Here

Examples of org.apache.oltu.oauth2.client.OAuthClient

   * @param url The url to call.
   * @return The body of the response.
   * @throws OAuthException If an error occurs while making the call.
   */
  protected String getServerResponse(String url) throws OAuthException{
    OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
    OAuthClientRequest request;
    try {
      request = new OAuthBearerClientRequest(url)
      .setAccessToken(getAccessToken())
      .buildQueryMessage();
    } catch (OAuthSystemException e1) {
      throw new OAuthException("An error occured while authenticating the user");
    }
    OAuthResourceResponse response;
    try {
      response = oAuthClient.resource(request, OAuth.HttpMethod.GET, OAuthResourceResponse.class);
    } catch (OAuthProblemException e) {
      throw new OAuthException("An error occured while authenticating the user");
    } catch (OAuthSystemException e) {
      throw new OAuthException("An error occured while authenticating the user");
    }
View Full Code Here

Examples of org.apache.oltu.oauth2.client.OAuthClient

      throw new OAuthException("No code provided");

    try {
      OAuthClientRequest request = OAuthClientRequest.tokenProvider(oauthParams.getProviderType()).setGrantType(oauthParams.getGrantType()).setClientId(oauthParams.getClientKey()).setClientSecret(oauthParams.getClientSecret()).setRedirectURI(oauthParams.getRedirectURI()).setCode(code).buildBodyMessage();

      OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

      // Send request to oauth server
      OAuthAccessTokenResponse oauthAccessTokenResponse = oAuthClient.accessToken(request, oauthParams.getTokenResponseClass());

      OAuthConsumer consumer = oauthParams.getNewOAuthConsumer(oauthAccessTokenResponse);
      return consumer;
    } catch (OAuthSystemException e) {
      // Error building request
View Full Code Here

Examples of org.apache.oltu.oauth2.client.OAuthClient

            .setRedirectURI(Common.REDIRECT_URL)
            .setClientId(Common.CLIENT_ID)
            .setClientSecret(Common.CLIENT_SECRET)
            .buildBodyMessage();

        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
        OAuthAccessTokenResponse response = oAuthClient.accessToken(request);
        assertNotNull(response.getAccessToken());
        assertNotNull(response.getExpiresIn());
    }
View Full Code Here

Examples of org.apache.oltu.oauth2.client.OAuthClient

            .setCode(Common.AUTHORIZATION_CODE)
            .setClientId(Common.CLIENT_ID)
            .setClientSecret("wrongSecret")
            .buildBodyMessage();

        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

        try {
            oAuthClient.accessToken(request);
            fail("exception expected");
        } catch (OAuthProblemException e) {
            assertEquals(OAuthError.TokenResponse.UNAUTHORIZED_CLIENT, e.getError());
        }
    }
View Full Code Here

Examples of org.apache.oltu.oauth2.client.OAuthClient

            .setGrantType(null)
            .setClientId(Common.CLIENT_ID)
            .setClientSecret(Common.CLIENT_SECRET)
            .buildBodyMessage();

        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

        try {
            oAuthClient.accessToken(request);
            fail("exception expected");
        } catch (OAuthProblemException e) {
            assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }
    }
View Full Code Here

Examples of org.apache.oltu.oauth2.client.OAuthClient

        OAuthClientRequest request = OAuthClientRequest
            .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT)
            .setClientId(Common.CLIENT_ID)
            .buildBodyMessage();

        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

        try {
            oAuthClient.accessToken(request);
            fail("exception expected");
        } catch (OAuthProblemException e) {
            assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }
    }
View Full Code Here

Examples of org.apache.oltu.oauth2.client.OAuthClient

            .setClientId("unknownid")
            .setClientSecret(Common.CLIENT_SECRET)
            .setRedirectURI(Common.REDIRECT_URL)
            .buildBodyMessage();

        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

        try {
            oAuthClient.accessToken(request);
            fail("exception expected");
        } catch (OAuthProblemException e) {
            assertEquals(OAuthError.TokenResponse.INVALID_CLIENT, e.getError());
        }
    }
View Full Code Here

Examples of org.apache.oltu.oauth2.client.OAuthClient

            .setRedirectURI(Common.REDIRECT_URL)
            .setClientId(Common.CLIENT_ID)
            .setClientSecret(Common.CLIENT_SECRET)
            .buildBodyMessage();

        OAuthClient oAuthclient = new OAuthClient(new URLConnectionClient());

        try {
            oAuthclient.accessToken(request);
            fail("exception expected");
        } catch (OAuthProblemException e) {
            assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }
    }
View Full Code Here

Examples of org.apache.oltu.oauth2.client.OAuthClient

            .setCode("unknown_code")
            .setClientId(Common.CLIENT_ID)
            .setClientSecret(Common.CLIENT_SECRET)
            .buildBodyMessage();

        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

        try {
            oAuthClient.accessToken(request);
            fail("exception expected");
        } catch (OAuthProblemException e) {
            assertEquals(OAuthError.TokenResponse.INVALID_GRANT, e.getError());
        }
    }
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.