Package com.nimbusds.oauth2.sdk.token

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


    String refreshTokenString = params.get("refresh_token");

    if (refreshTokenString == null || refreshTokenString.trim().isEmpty())
      throw new ParseException("Missing or empty \"refresh_token\" parameter", OAuth2Error.INVALID_REQUEST);

    RefreshToken refreshToken = new RefreshToken(refreshTokenString);

    return new RefreshTokenGrant(refreshToken);
  }
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

  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

        }
      };

    } else if (tokenTypeHint.equals("access_token")) {

      token = new TypelessAccessToken(tokenValue);

    } else if (tokenTypeHint.equals("refresh_token")) {

      token = new RefreshToken(tokenValue);
    }
View Full Code Here


  public void testComputeAgainstSpecExample()
    throws Exception {

    AccessToken token = new TypelessAccessToken("jHkWEdUXMU1BwAsC4vtUsZwnNvTIxEl0z9K3vx5KF0Y");

    AccessTokenHash computedHash = AccessTokenHash.compute(token, JWSAlgorithm.RS256);

    AccessTokenHash expectedHash = new AccessTokenHash("77QmUPtjPfzWtF2AnpK9RQ");
View Full Code Here

  }


  public void testEquality() {

    AccessToken token = new TypelessAccessToken("12345678");

    AccessTokenHash hash1 = AccessTokenHash.compute(token, JWSAlgorithm.HS512);

    AccessTokenHash hash2 = AccessTokenHash.compute(token, JWSAlgorithm.HS512);
View Full Code Here

  }


  public void testUnsupportedJWSAlg() {

    AccessToken token = new TypelessAccessToken("12345678");

    assertNull(AccessTokenHash.compute(token, new JWSAlgorithm("no-such-alg")));
  }
View Full Code Here

TOP

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

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.