Package com.nimbusds.oauth2.sdk.token

Examples of com.nimbusds.oauth2.sdk.token.TokenPair


  public void testWithRefreshTokenAndClientAuth()
    throws Exception {

    URI endpointURI = new URI("https://c2id.com/token/revoke");
    Token token = new RefreshToken();
    ClientAuthentication clientAuth = new ClientSecretBasic(new ClientID("123"), new Secret("secret"));

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


  public void testWithAccessToken()
    throws Exception {

    URI endpointURI = new URI("https://c2id.com/token/revoke");
    Token token = new BearerAccessToken();

    TokenRevocationRequest request = new TokenRevocationRequest(endpointURI, null, token);
    assertEquals(endpointURI, request.getEndpointURI());
    assertNull(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());
    assertNull(httpRequest.getAuthorization());

    assertEquals(token.getValue(), httpRequest.getQueryParameters().get("token"));
    assertEquals("access_token", httpRequest.getQueryParameters().get("token_type_hint"));
    assertEquals(2, httpRequest.getQueryParameters().size());
  }
View Full Code Here

  public void testWithAccessTokenAndClientAuth()
    throws Exception {

    URI endpointURI = new URI("https://c2id.com/token/revoke");
    Token token = new BearerAccessToken();
    ClientAuthentication clientAuth = new ClientSecretBasic(new ClientID("123"), new Secret("secret"));

    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("access_token", httpRequest.getQueryParameters().get("token_type_hint"));
    assertEquals(2, httpRequest.getQueryParameters().size());

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

  public void testWithRefreshToken()
    throws Exception {

    URI endpointURI = new URI("https://c2id.com/token/revoke");
    Token token = new RefreshToken();

    TokenRevocationRequest request = new TokenRevocationRequest(endpointURI, null, token);
    assertEquals(endpointURI, request.getEndpointURI());
    assertNull(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());
    assertNull(httpRequest.getAuthorization());

    assertEquals(token.getValue(), httpRequest.getQueryParameters().get("token"));
    assertEquals("refresh_token", httpRequest.getQueryParameters().get("token_type_hint"));
    assertEquals(2, httpRequest.getQueryParameters().size());
  }
View Full Code Here

   *
   * @return The access and refresh token pair. Must not be {@code null}.
   */
  public TokenPair getTokenPair() {

    return new TokenPair(accessToken, refreshToken);
  }
View Full Code Here

  public void testAltConstructor() {

    AccessToken accessToken = new BearerAccessToken();
    RefreshToken refreshToken = new RefreshToken();
    TokenPair tokenPair = new TokenPair(accessToken, refreshToken);

    AccessTokenResponse response = new AccessTokenResponse(tokenPair);

    assertEquals(accessToken, response.getAccessToken());
    assertEquals(refreshToken, response.getRefreshToken());
View Full Code Here


  public void testAltConstructorMinimal() {

    AccessToken accessToken = new BearerAccessToken();
    TokenPair tokenPair = new TokenPair(accessToken, null);

    AccessTokenResponse response = new AccessTokenResponse(tokenPair);

    assertEquals(accessToken, response.getAccessToken());
    assertNull(response.getRefreshToken());
View Full Code Here


  public void testAltConstructorWithCustomParams() {

    AccessToken accessToken = new BearerAccessToken();
    TokenPair tokenPair = new TokenPair(accessToken, null);
    Map<String,Object> customParams = new HashMap<>();
    customParams.put("sub_sid", "abc");

    AccessTokenResponse response = new AccessTokenResponse(tokenPair, customParams);
    assertEquals(accessToken, response.getAccessToken());
View Full Code Here

    assertEquals("abc", (String)atr.getCustomParams().get("sub_sid"));
    assertEquals(10, ((Number)atr.getCustomParams().get("priority")).intValue());
    assertEquals(2, atr.getCustomParams().size());

    // Test pair getter
    TokenPair pair = atr.getTokenPair();
    assertEquals(accessToken, pair.getAccessToken());
    assertEquals(refreshToken, pair.getRefreshToken());

    httpResponse = atr.toHTTPResponse();

    assertEquals(CommonContentTypes.APPLICATION_JSON, httpResponse.getContentType());
    assertEquals("no-store", httpResponse.getCacheControl());
View Full Code Here

    AccessToken accessToken = atr.getAccessToken();
    assertEquals(accessTokenString, accessToken.getValue());
    assertNull(accessToken.getScope());

    // Test pair getter
    TokenPair pair = atr.getTokenPair();
    assertEquals(accessToken, pair.getAccessToken());

    httpResponse = atr.toHTTPResponse();

    assertEquals(CommonContentTypes.APPLICATION_JSON, httpResponse.getContentType());
    assertEquals("no-store", httpResponse.getCacheControl());
View Full Code Here

TOP

Related Classes of com.nimbusds.oauth2.sdk.token.TokenPair

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.