Package org.apache.oltu.oauth2.client.response

Examples of org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse


                    .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);
View Full Code Here


      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

            .setPassword(Common.PASSWORD)
            .buildBodyMessage();

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

        OAuthJSONAccessTokenResponse response = oAuthClient.accessToken(request);

        assertNotNull(response.getAccessToken());
    }
View Full Code Here

    Logger logger = LoggerFactory.getLogger(OAuthJSONAccessTokenResponse.class);

    @Test
    public void testGetAccessToken() throws Exception {
        logger.info("Running test: testGetAccessToken " + this.getClass().getName());
        OAuthJSONAccessTokenResponse r = null;
        try {
            r = new OAuthJSONAccessTokenResponse();
            r.init(TestUtils.VALID_JSON_RESPONSE,
                OAuth.ContentType.JSON, 200);
        } catch (OAuthProblemException e) {
            fail("Exception not expected");
        }

        Assert.assertEquals(TestUtils.ACCESS_TOKEN, r.getAccessToken());

        try {
            r = new OAuthJSONAccessTokenResponse();
            r.init(TestUtils.ERROR_JSON_BODY,
                OAuth.ContentType.JSON, 200);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertNotNull(e.getError());
        }
View Full Code Here

        }
    }

    @Test
    public void testGetExpiresIn() throws Exception {
        OAuthJSONAccessTokenResponse r = null;

        try {
            r = new OAuthJSONAccessTokenResponse();
            r.init(TestUtils.VALID_JSON_RESPONSE,
                OAuth.ContentType.JSON, 200);
        } catch (OAuthProblemException e) {
            fail("Exception not expected");
        }

        Assert.assertEquals(TestUtils.EXPIRES_IN, r.getExpiresIn());

        try {
            new OAuthJSONAccessTokenResponse();
            r.init(TestUtils.ERROR_JSON_BODY,
                OAuth.ContentType.JSON, 200);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertNotNull(e.getError());
        }
View Full Code Here

        }
    }

    @Test
    public void testGetScope() throws Exception {
        OAuthJSONAccessTokenResponse r = null;
        try {
            r = new OAuthJSONAccessTokenResponse();
            r.init(TestUtils.VALID_JSON_RESPONSE,
                OAuth.ContentType.JSON, 200);
        } catch (OAuthProblemException e) {
            fail("Exception not expected");
        }

        Assert.assertEquals(TestUtils.SCOPE, r.getScope());

        try {
            new OAuthJSONAccessTokenResponse();
            r.init(TestUtils.ERROR_JSON_BODY,
                OAuth.ContentType.JSON, 200);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertNotNull(e.getError());
View Full Code Here

        }
    }

    @Test
    public void testGetRefreshToken() throws Exception {
        OAuthJSONAccessTokenResponse r = null;
        try {
            r = new OAuthJSONAccessTokenResponse();
            r.init(TestUtils.VALID_JSON_RESPONSE,
                OAuth.ContentType.JSON, 200);
        } catch (OAuthProblemException e) {
            fail("Exception not expected");
        }

        Assert.assertEquals(TestUtils.REFRESH_TOKEN, r.getRefreshToken());

        try {
            new OAuthJSONAccessTokenResponse();
            r.init(TestUtils.ERROR_JSON_BODY,
                OAuth.ContentType.JSON, 200);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertNotNull(e.getError());
        }
View Full Code Here

    }

    @Test
    public void testSetBody() throws Exception {

        OAuthJSONAccessTokenResponse r = null;
        try {
            r = new OAuthJSONAccessTokenResponse();
            r.init(TestUtils.VALID_JSON_RESPONSE,
                OAuth.ContentType.JSON, 200);
        } catch (OAuthProblemException e) {
            fail("Exception not expected");
        }

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

        Assert.assertEquals(TestUtils.EXPIRES_IN, expiresIn);
        Assert.assertEquals(TestUtils.ACCESS_TOKEN, accessToken);

        try {
            new OAuthJSONAccessTokenResponse();
            r.init(TestUtils.ERROR_JSON_BODY,
                OAuth.ContentType.JSON, 200);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }
View Full Code Here

            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

      .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");
    }
    return response.getBody();
  }
View Full Code Here

TOP

Related Classes of org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse

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.