Package com.nimbusds.oauth2.sdk.http

Examples of com.nimbusds.oauth2.sdk.http.HTTPRequest


 
 
  public void testCodeGrantWithBasicSecret()
    throws Exception {
 
    HTTPRequest httpRequest = new HTTPRequest(HTTPRequest.Method.POST, new URL("https://connect2id.com/token/"));
    httpRequest.setContentType(CommonContentTypes.APPLICATION_URLENCODED);
   
    String authBasicString = "czZCaGRSa3F0MzpnWDFmQmF0M2JW";
    httpRequest.setAuthorization("Basic " + authBasicString);
   
    String postBody =
      "grant_type=authorization_code" +
      "&code=SplxlOBeZQQYbYS6WxSbIA" +
      "&redirect_uri=https%3A%2F%2Fclient.example.com%2Fcb";
   
    httpRequest.setQuery(postBody);
   
    TokenRequest tr = TokenRequest.parse(httpRequest);

    assertTrue(new URI("https://connect2id.com/token/").equals(tr.getEndpointURI()));

    ClientSecretBasic authBasic = (ClientSecretBasic)tr.getClientAuthentication();
    assertEquals(ClientAuthenticationMethod.CLIENT_SECRET_BASIC, authBasic.getMethod());
    assertEquals("Basic " + authBasicString, authBasic.toHTTPAuthorizationHeader());
    assertEquals("s6BhdRkqt3", authBasic.getClientID().getValue());

    AuthorizationCodeGrant codeGrant = (AuthorizationCodeGrant)tr.getAuthorizationGrant();
    assertEquals(GrantType.AUTHORIZATION_CODE, codeGrant.getType());
    assertEquals("SplxlOBeZQQYbYS6WxSbIA", codeGrant.getAuthorizationCode().getValue());
    assertEquals("https://client.example.com/cb", codeGrant.getRedirectionURI().toString());

    assertNull(tr.getClientID());
   
    httpRequest = tr.toHTTPRequest();
   
    assertTrue(new URL("https://connect2id.com/token/").equals(httpRequest.getURL()));
    assertEquals(CommonContentTypes.APPLICATION_URLENCODED, httpRequest.getContentType());
    assertEquals("Basic " + authBasicString, httpRequest.getAuthorization());
    assertEquals("authorization_code", httpRequest.getQueryParameters().get("grant_type"));
    assertEquals("SplxlOBeZQQYbYS6WxSbIA", httpRequest.getQueryParameters().get("code"));
    assertEquals("https://client.example.com/cb", httpRequest.getQueryParameters().get("redirect_uri"));
    assertEquals(3, httpRequest.getQueryParameters().size());
  }
View Full Code Here


 
 
  public void testParseRefreshTokenGrantWithBasicSecret()
    throws Exception {
 
    HTTPRequest httpRequest = new HTTPRequest(HTTPRequest.Method.POST, new URL("https://connect2id.com/token/"));
    httpRequest.setContentType(CommonContentTypes.APPLICATION_URLENCODED);
   
    final String authBasicString = "czZCaGRSa3F0MzpnWDFmQmF0M2JW";
    httpRequest.setAuthorization("Basic " + authBasicString);
   
    final String postBody =
      "grant_type=refresh_token" +
      "&refresh_token=tGzv3JOkF0XG5Qx2TlKWIA";
   
    httpRequest.setQuery(postBody);
   
    TokenRequest tr = TokenRequest.parse(httpRequest);

    assertTrue(new URI("https://connect2id.com/token/").equals(tr.getEndpointURI()));

    ClientSecretBasic authBasic = (ClientSecretBasic)tr.getClientAuthentication();
    assertEquals(ClientAuthenticationMethod.CLIENT_SECRET_BASIC, authBasic.getMethod());
    assertEquals("Basic " + authBasicString, authBasic.toHTTPAuthorizationHeader());
    assertEquals("s6BhdRkqt3", authBasic.getClientID().getValue());

    RefreshTokenGrant rtGrant = (RefreshTokenGrant)tr.getAuthorizationGrant();
    assertEquals(GrantType.REFRESH_TOKEN, rtGrant.getType());
    assertEquals("tGzv3JOkF0XG5Qx2TlKWIA", rtGrant.getRefreshToken().getValue());
   
    httpRequest = tr.toHTTPRequest();

    assertTrue(new URL("https://connect2id.com/token/").equals(httpRequest.getURL()));
    assertEquals(CommonContentTypes.APPLICATION_URLENCODED, httpRequest.getContentType());
    assertEquals("Basic " + authBasicString, httpRequest.getAuthorization());
    assertEquals(postBody, httpRequest.getQuery());
  }
View Full Code Here


  public void testParsePasswordCredentialsGrant()
    throws Exception {

    HTTPRequest httpRequest = new HTTPRequest(HTTPRequest.Method.POST, new URL("https://connect2id.com/token/"));
    httpRequest.setContentType(CommonContentTypes.APPLICATION_URLENCODED);

    final String postBody = "grant_type=password&username=johndoe&password=A3ddj3w";

    httpRequest.setQuery(postBody);

    TokenRequest tr = TokenRequest.parse(httpRequest);

    assertTrue(new URI("https://connect2id.com/token/").equals(tr.getEndpointURI()));

    assertNull(tr.getClientAuthentication());
    assertNull(tr.getClientID());

    ResourceOwnerPasswordCredentialsGrant pwdGrant = (ResourceOwnerPasswordCredentialsGrant)tr.getAuthorizationGrant();
    assertEquals(GrantType.PASSWORD, pwdGrant.getType());
    assertEquals("johndoe", pwdGrant.getUsername());
    assertEquals("A3ddj3w", pwdGrant.getPassword().getValue());

    assertNull(tr.getScope());

    httpRequest = tr.toHTTPRequest();

    assertTrue(new URL("https://connect2id.com/token/").equals(httpRequest.getURL()));
    assertEquals(CommonContentTypes.APPLICATION_URLENCODED, httpRequest.getContentType());
    assertNull(httpRequest.getAuthorization());
    assertEquals("password", httpRequest.getQueryParameters().get("grant_type"));
    assertEquals("johndoe", httpRequest.getQueryParameters().get("username"));
    assertEquals("A3ddj3w", httpRequest.getQueryParameters().get("password"));
    assertEquals(3, httpRequest.getQueryParameters().size());
  }
View Full Code Here


  public void testParsePasswordCredentialsGrantWithClientAuthentication()
    throws Exception {

    HTTPRequest httpRequest = new HTTPRequest(HTTPRequest.Method.POST, new URL("https://connect2id.com/token/"));
    httpRequest.setContentType(CommonContentTypes.APPLICATION_URLENCODED);

    final String authBasicString = "czZCaGRSa3F0MzpnWDFmQmF0M2JW";
    httpRequest.setAuthorization("Basic " + authBasicString);

    final String postBody = "grant_type=password&username=johndoe&password=A3ddj3w";

    httpRequest.setQuery(postBody);

    TokenRequest tr = TokenRequest.parse(httpRequest);

    assertTrue(new URI("https://connect2id.com/token/").equals(tr.getEndpointURI()));

    ClientSecretBasic authBasic = (ClientSecretBasic)tr.getClientAuthentication();
    assertEquals(ClientAuthenticationMethod.CLIENT_SECRET_BASIC, authBasic.getMethod());
    assertEquals("Basic " + authBasicString, authBasic.toHTTPAuthorizationHeader());
    assertEquals("s6BhdRkqt3", authBasic.getClientID().getValue());

    ResourceOwnerPasswordCredentialsGrant pwdGrant = (ResourceOwnerPasswordCredentialsGrant)tr.getAuthorizationGrant();
    assertEquals(GrantType.PASSWORD, pwdGrant.getType());
    assertEquals("johndoe", pwdGrant.getUsername());
    assertEquals("A3ddj3w", pwdGrant.getPassword().getValue());

    assertNull(tr.getScope());

    httpRequest = tr.toHTTPRequest();

    assertTrue(new URL("https://connect2id.com/token/").equals(httpRequest.getURL()));
    assertEquals(CommonContentTypes.APPLICATION_URLENCODED, httpRequest.getContentType());
    assertEquals("Basic " + authBasicString, httpRequest.getAuthorization());
    assertEquals("password", httpRequest.getQueryParameters().get("grant_type"));
    assertEquals("johndoe", httpRequest.getQueryParameters().get("username"));
    assertEquals("A3ddj3w", httpRequest.getQueryParameters().get("password"));
    assertEquals(3, httpRequest.getQueryParameters().size());
  }
View Full Code Here


  public void testParseClientCredentialsGrant()
    throws Exception {

    HTTPRequest httpRequest = new HTTPRequest(HTTPRequest.Method.POST, new URL("https://connect2id.com/token/"));
    httpRequest.setContentType(CommonContentTypes.APPLICATION_URLENCODED);

    final String authBasicString = "czZCaGRSa3F0MzpnWDFmQmF0M2JW";
    httpRequest.setAuthorization("Basic " + authBasicString);

    final String postBody = "grant_type=client_credentials";

    httpRequest.setQuery(postBody);

    TokenRequest tr = TokenRequest.parse(httpRequest);

    assertTrue(new URI("https://connect2id.com/token/").equals(tr.getEndpointURI()));

    ClientSecretBasic authBasic = (ClientSecretBasic)tr.getClientAuthentication();
    assertEquals(ClientAuthenticationMethod.CLIENT_SECRET_BASIC, authBasic.getMethod());
    assertEquals("Basic " + authBasicString, authBasic.toHTTPAuthorizationHeader());
    assertEquals("s6BhdRkqt3", authBasic.getClientID().getValue());

    ClientCredentialsGrant clientCredentialsGrant = (ClientCredentialsGrant)tr.getAuthorizationGrant();
    assertEquals(GrantType.CLIENT_CREDENTIALS, clientCredentialsGrant.getType());

    assertNull(tr.getScope());

    httpRequest = tr.toHTTPRequest();

    assertTrue(new URL("https://connect2id.com/token/").equals(httpRequest.getURL()));
    assertEquals(CommonContentTypes.APPLICATION_URLENCODED, httpRequest.getContentType());
    assertEquals("Basic " + authBasicString, httpRequest.getAuthorization());
    assertEquals(postBody, httpRequest.getQuery());
  }
View Full Code Here


  public void testParseClientCredentialsGrantMissingAuthentication()
    throws Exception {

    HTTPRequest httpRequest = new HTTPRequest(HTTPRequest.Method.POST, new URL("https://connect2id.com/token/"));
    httpRequest.setContentType(CommonContentTypes.APPLICATION_URLENCODED);
    final String postBody = "grant_type=client_credentials";

    httpRequest.setQuery(postBody);

    try {
      TokenRequest.parse(httpRequest);
      fail();
    } catch (ParseException e) {
View Full Code Here

    Secret secret = new Secret("secret");
    ClientSecretPost clientAuthentication = new ClientSecretPost(clientId,secret);
    AuthorizationGrant grant = new AuthorizationCodeGrant(code,redirectUri);
    TokenRequest request = new TokenRequest(endpointUri,clientAuthentication,grant);

    HTTPRequest httpRequest = request.toHTTPRequest();
    TokenRequest reconstructedRequest = TokenRequest.parse(httpRequest);
   
    assertEquals("client", reconstructedRequest.getClientAuthentication().getClientID().getValue());
    assertEquals("secret", ((ClientSecretPost)reconstructedRequest.getClientAuthentication()).getClientSecret().getValue());
    assertEquals(code, ((AuthorizationCodeGrant)reconstructedRequest.getAuthorizationGrant()).getAuthorizationCode());
View Full Code Here


  public void testParseFromHTTPRequest()
    throws Exception {

    HTTPRequest httpRequest = new HTTPRequest(HTTPRequest.Method.GET, new URL("http://c2id.com/reg/123"));
    httpRequest.setAuthorization("Bearer abc");

    BearerAccessToken accessToken = BearerAccessToken.parse(httpRequest);

    assertEquals("abc", accessToken.getValue());
  }
View Full Code Here

    } catch (MalformedURLException e) {

      throw new SerializeException(e.getMessage(), e);
    }
 
    HTTPRequest httpRequest = new HTTPRequest(HTTPRequest.Method.POST, endpointURL);

    if (getAccessToken() != null) {
      httpRequest.setAuthorization(getAccessToken().toAuthorizationHeader());
    }

    httpRequest.setContentType(CommonContentTypes.APPLICATION_JSON);

    JSONObject content = metadata.toJSONObject();

    if (softwareStatement != null) {

      // Signed state check done in constructor
      content.put("software_statement", softwareStatement.serialize());
    }

    httpRequest.setQuery(content.toString());

    return httpRequest;
  }
View Full Code Here


  public void testParseFromHTTPRequestMissing()
    throws Exception {

    HTTPRequest httpRequest = new HTTPRequest(HTTPRequest.Method.GET, new URL("http://c2id.com/reg/123"));

    try {
      BearerAccessToken.parse(httpRequest);
      fail();
View Full Code Here

TOP

Related Classes of com.nimbusds.oauth2.sdk.http.HTTPRequest

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.