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());
}