Package com.nimbusds.oauth2.sdk.http

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


    TokenRevocationRequest request = new TokenRevocationRequest(endpointURI, clientAuth, token);
    assertEquals(endpointURI, request.getEndpointURI());
    assertEquals(clientAuth, request.getClientAuthentication());
    assertEquals(token, request.getToken());

    HTTPRequest httpRequest = request.toHTTPRequest();
    assertEquals(HTTPRequest.Method.POST, httpRequest.getMethod());
    assertEquals(endpointURI.toURL().toString(), httpRequest.getURL().toString());
    assertEquals(CommonContentTypes.APPLICATION_URLENCODED, httpRequest.getContentType());

    assertEquals(token.getValue(), httpRequest.getQueryParameters().get("token"));
    assertEquals("refresh_token", httpRequest.getQueryParameters().get("token_type_hint"));
    assertEquals(2, httpRequest.getQueryParameters().size());

    ClientSecretBasic basicAuth = ClientSecretBasic.parse(httpRequest.getAuthorization());
    assertEquals("123", basicAuth.getClientID().getValue());
    assertEquals("secret", basicAuth.getClientSecret().getValue());
  }
View Full Code Here



  public void testWithUnknownToken()
    throws Exception {

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

    Map<String,String> queryParams = new HashMap<>();
    queryParams.put("token", "abc");
    httpRequest.setQuery(URLUtils.serializeParameters(queryParams));

    TokenRevocationRequest request = TokenRevocationRequest.parse(httpRequest);
    assertEquals("abc", request.getToken().getValue());
    assertFalse(request.getToken() instanceof AccessToken);
    assertFalse(request.getToken() instanceof RefreshToken);
View Full Code Here

    } catch (MalformedURLException e) {

      throw new SerializeException(e.getMessage(), e);
    }
 
    HTTPRequest httpRequest = new HTTPRequest(HTTPRequest.Method.DELETE, endpointURL);
    httpRequest.setAuthorization(getAccessToken().toAuthorizationHeader());
    return httpRequest;
  }
View Full Code Here

    } catch (MalformedURLException e) {

      throw new SerializeException(e.getMessage(), e);
    }

    HTTPRequest httpRequest = new HTTPRequest(HTTPRequest.Method.POST, url);
    httpRequest.setContentType(CommonContentTypes.APPLICATION_URLENCODED);

    Map<String,String> params = new HashMap<>();
    params.put("token", token.getValue());

    if (token instanceof AccessToken) {
      params.put("token_type_hint", "access_token");
    } else if (token instanceof RefreshToken) {
      params.put("token_type_hint", "refresh_token");
    }

    httpRequest.setQuery(URLUtils.serializeParameters(params));

    if (getClientAuthentication() != null)
      getClientAuthentication().applyTo(httpRequest);

    return httpRequest;
View Full Code Here

    assertEquals(clientAuth, request.getClientAuthentication());
    assertNull(request.getClientID());
    assertEquals(grant, request.getAuthorizationGrant());
    assertEquals(scope, request.getScope());

    HTTPRequest httpRequest = request.toHTTPRequest();
    assertEquals(uri.toURL(), httpRequest.getURL());
    assertEquals(HTTPRequest.Method.POST, httpRequest.getMethod());
    ClientSecretBasic basic = ClientSecretBasic.parse(httpRequest.getAuthorization());
    assertEquals("123", basic.getClientID().getValue());
    assertEquals("secret", basic.getClientSecret().getValue());
    Map<String,String> params = httpRequest.getQueryParameters();
    assertEquals(GrantType.AUTHORIZATION_CODE.getValue(), params.get("grant_type"));
    assertEquals("abc", params.get("code"));
    assertTrue(Scope.parse("openid email").containsAll(Scope.parse(params.get("scope"))));
    assertEquals(3, params.size());
  }
View Full Code Here

    assertEquals(clientAuth, request.getClientAuthentication());
    assertNull(request.getClientID());
    assertEquals(grant, request.getAuthorizationGrant());
    assertNull(request.getScope());

    HTTPRequest httpRequest = request.toHTTPRequest();
    assertEquals(uri.toURL(), httpRequest.getURL());
    assertEquals(HTTPRequest.Method.POST, httpRequest.getMethod());
    ClientSecretBasic basic = ClientSecretBasic.parse(httpRequest.getAuthorization());
    assertEquals("123", basic.getClientID().getValue());
    assertEquals("secret", basic.getClientSecret().getValue());
    Map<String,String> params = httpRequest.getQueryParameters();
    assertEquals(GrantType.AUTHORIZATION_CODE.getValue(), params.get("grant_type"));
    assertEquals("abc", params.get("code"));
    assertEquals(2, params.size());
  }
View Full Code Here

    assertNull(request.getClientAuthentication());
    assertEquals(clientID, request.getClientID());
    assertEquals(grant, request.getAuthorizationGrant());
    assertNull(request.getScope());

    HTTPRequest httpRequest = request.toHTTPRequest();
    assertEquals(uri.toURL(), httpRequest.getURL());
    assertEquals(HTTPRequest.Method.POST, httpRequest.getMethod());
    assertNull(httpRequest.getAuthorization());
    Map<String,String> params = httpRequest.getQueryParameters();
    assertEquals(GrantType.AUTHORIZATION_CODE.getValue(), params.get("grant_type"));
    assertEquals("abc", params.get("code"));
    assertEquals("123", params.get("client_id"));
    assertEquals("http://example.com/in", params.get("redirect_uri"));
    assertEquals(4, params.size());
View Full Code Here

    assertNull(request.getClientAuthentication());
    assertEquals(clientID, request.getClientID());
    assertEquals(grant, request.getAuthorizationGrant());
    assertNull(request.getScope());

    HTTPRequest httpRequest = request.toHTTPRequest();
    assertEquals(uri.toURL(), httpRequest.getURL());
    assertEquals(HTTPRequest.Method.POST, httpRequest.getMethod());
    assertNull(httpRequest.getAuthorization());
    Map<String,String> params = httpRequest.getQueryParameters();
    assertEquals(GrantType.AUTHORIZATION_CODE.getValue(), params.get("grant_type"));
    assertEquals("abc", params.get("code"));
    assertEquals("123", params.get("client_id"));
    assertEquals("http://example.com/in", params.get("redirect_uri"));
    assertEquals(4, params.size());
View Full Code Here

    assertNull(tokenRequest.getClientAuthentication());
    assertNull(tokenRequest.getClientID());
    assertEquals(grant, tokenRequest.getAuthorizationGrant());
    assertEquals(scope, tokenRequest.getScope());

    HTTPRequest httpRequest = tokenRequest.toHTTPRequest();
    assertEquals(uri.toURL(), httpRequest.getURL());
    assertEquals(HTTPRequest.Method.POST, httpRequest.getMethod());
    assertNull(httpRequest.getAuthorization());
    Map<String,String> params = httpRequest.getQueryParameters();
    assertEquals(GrantType.PASSWORD.getValue(), params.get("grant_type"));
    assertEquals("alice", params.get("username"));
    assertEquals("secret", params.get("password"));
    assertTrue(Scope.parse("openid email").containsAll(Scope.parse(params.get("scope"))));
    assertEquals(4, params.size());
View Full Code Here

    assertNull(tokenRequest.getClientAuthentication());
    assertNull(tokenRequest.getClientID());
    assertEquals(grant, tokenRequest.getAuthorizationGrant());
    assertNull(tokenRequest.getScope());

    HTTPRequest httpRequest = tokenRequest.toHTTPRequest();
    assertEquals(uri.toURL(), httpRequest.getURL());
    assertEquals(HTTPRequest.Method.POST, httpRequest.getMethod());
    assertNull(httpRequest.getAuthorization());
    Map<String,String> params = httpRequest.getQueryParameters();
    assertEquals(GrantType.PASSWORD.getValue(), params.get("grant_type"));
    assertEquals("alice", params.get("username"));
    assertEquals("secret", params.get("password"));
    assertEquals(3, params.size());
  }
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.