Package org.apache.amber.oauth2.client.request

Examples of org.apache.amber.oauth2.client.request.OAuthClientRequest$TokenRequestBuilder


        }
    }

    @Test
    public void testInvalidClient() throws Exception {
        OAuthClientRequest request = OAuthClientRequest
            .tokenLocation(Common.UNAUTHENTICATED_ACCESS_TOKEN_ENDPOINT)
            .setGrantType(GrantType.AUTHORIZATION_CODE)
            .setCode(Common.AUTHORIZATION_CODE)
            .setClientId("unknownid")
            .setRedirectURI(Common.REDIRECT_URL)
View Full Code Here


        }
    }

    @Test
    public void testInvalidGrantType() throws Exception {
        OAuthClientRequest request = OAuthClientRequest
            .tokenLocation(Common.UNAUTHENTICATED_ACCESS_TOKEN_ENDPOINT)
            .setParameter(OAuth.OAUTH_GRANT_TYPE, "unknown_grant_type")
            .setCode(Common.AUTHORIZATION_CODE)
            .setRedirectURI(Common.REDIRECT_URL)
            .setClientId(Common.CLIENT_ID)
View Full Code Here

        }
    }

    @Test
    public void testInvalidCode() throws Exception {
        OAuthClientRequest request = OAuthClientRequest
            .tokenLocation(Common.UNAUTHENTICATED_ACCESS_TOKEN_ENDPOINT)
            .setGrantType(GrantType.AUTHORIZATION_CODE)
            .setRedirectURI(Common.REDIRECT_URL)
            .setCode("unknown_code")
            .setClientId(Common.CLIENT_ID)
View Full Code Here

            this.parameters.put(OAuthRegistration.Request.REDIRECT_URL, uri);
            return this;
        }

        public OAuthClientRequest buildJSONMessage() throws OAuthSystemException {
            OAuthClientRequest request = new OAuthClientRegistrationRequest(url);
            this.applier = new JSONBodyParametersApplier();
            return (OAuthClientRequest)applier.applyOAuthParameters(request, parameters);
        }
View Full Code Here

public class OAuthClientTest {

    public static void main(String[] args) throws OAuthSystemException, IOException {

        try {
            OAuthClientRequest request = OAuthClientRequest
                .authorizationProvider(OAuthProviderType.FACEBOOK)
                .setClientId("131804060198305")
                .setRedirectURI("http://localhost:8080/")
                .buildQueryMessage();

            //in web application you make redirection to uri:
            System.out.println("Visit: " + request.getLocationUri() + "\nand grant permission");

            System.out.print("Now enter the OAuth code you have received in redirect uri ");
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String code = br.readLine();
View Full Code Here

        browserFacade.open(new URI(createAuthorizationURL(parameters, TOKEN)).toURL());
        parameters.waitingForAuthorization();
    }

    void refreshAccessToken(OAuth2Parameters parameters) throws OAuthProblemException, OAuthSystemException {
        OAuthClientRequest accessTokenRequest = OAuthClientRequest
                .tokenLocation(parameters.accessTokenUri)
                .setGrantType(GrantType.REFRESH_TOKEN)
                .setClientId(parameters.clientId)
                .setClientSecret(parameters.clientSecret)
                .setRefreshToken(parameters.refreshToken)
View Full Code Here

    private void getAccessTokenAndSaveToProfile(UserBrowserFacade browserFacade, OAuth2Parameters parameters, String authorizationCode) {
        if (authorizationCode != null) {
            try {
                parameters.receivedAuthorizationCode();
                OAuthClientRequest accessTokenRequest = OAuthClientRequest
                        .tokenLocation(parameters.accessTokenUri)
                        .setGrantType(GrantType.AUTHORIZATION_CODE)
                        .setClientId(parameters.clientId)
                        .setClientSecret(parameters.clientSecret)
                        .setRedirectURI(parameters.redirectUri)
View Full Code Here

   * @param request
   * @return request URI
   */
  public String getEndUserAuthorizationRequestUri(final HttpServletRequest request) {
   
    OAuthClientRequest oauthClientRequest;
   
    try {
     
      oauthClientRequest = OAuthClientRequest
        .authorizationLocation(authorizationLocation)
        .setClientId(clientId)
        .setRedirectURI(getAbsoluteUrl(request, redirectUri))
        .setScope(getScope())
        .setResponseType(getResponseType())
        .setState(getState())
        .buildQueryMessage();

      logger.log(Level.INFO, "Authorization request location URI: {0}", oauthClientRequest.getLocationUri());
   
      return oauthClientRequest.getLocationUri();
     
    } catch (OAuthSystemException ex) {
      logger.log(Level.SEVERE, null, ex);
    }
   
View Full Code Here

        logger.log(Level.SEVERE, "Could not get code from request, cancelling authorization process");
        return null;
       
      }
     
      OAuthClientRequest clientReq = OAuthClientRequest
        .tokenLocation(tokenLocation)
        .setGrantType(getGrantType())
        .setClientId(clientId)
        .setClientSecret(clientSecret)
        .setRedirectURI(getAbsoluteUrl(request, redirectUri))
        .setCode(getCode(request))
      .buildBodyMessage();

      logger.log(Level.INFO, "Request body: {0}", clientReq.getBody());

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

      tokenResponse = oAuthClient.accessToken(clientReq, tokenResponseClass);
     
View Full Code Here

     
      if (accessToken != null) {
       
        final String accessTokenParameterKey = this.getAccessTokenParameterKey();
       
        OAuthClientRequest clientReq = new OAuthBearerClientRequest(getUserResourceUri()) {
       
          @Override
          public OAuthBearerClientRequest setAccessToken(String accessToken) {
              this.parameters.put(accessTokenParameterKey, accessToken);
              return this;
          }
       
        }
          .setAccessToken(accessToken)
          .buildQueryMessage();
       
        // needed for LinkedIn
        clientReq.setHeader("x-li-format", "json");
       
        logger.log(Level.INFO, "User info request: {0}", clientReq.getLocationUri());
       
        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

        userResponse = oAuthClient.resource(clientReq, "GET", OAuthResourceResponse.class);
        logger.log(Level.INFO, "User info response: {0}", userResponse);
View Full Code Here

TOP

Related Classes of org.apache.amber.oauth2.client.request.OAuthClientRequest$TokenRequestBuilder

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.