protected MultivaluedMap<String, String> createRedirectState(
     ContainerRequestContext rc, UriInfo ui) {
   if (clientStateManager == null) {
     return new MetadataMap<String, String>();
   }
   String codeVerifier = null;
   MultivaluedMap<String, String> codeRequestState = toCodeRequestState(rc, ui);
   if (codeVerifierTransformer != null) {
     codeVerifier = Base64UrlUtility.encode(CryptoUtils.generateSecureRandomBytes(32));
     codeRequestState.putSingle(OAuthConstants.AUTHORIZATION_CODE_VERIFIER, codeVerifier);
   }
   MultivaluedMap<String, String> redirectState =
       clientStateManager.toRedirectState(mc, codeRequestState);
   if (codeVerifier != null) {
     redirectState.putSingle(OAuthConstants.AUTHORIZATION_CODE_VERIFIER, codeVerifier);
   }
   return redirectState;
 }
  protected void processCodeResponse(
      ContainerRequestContext rc, UriInfo ui, MultivaluedMap<String, String> requestParams) {

    MultivaluedMap<String, String> state = null;
    if (clientStateManager != null) {
      state = clientStateManager.fromRedirectState(mc, requestParams);
    }

    String codeParam = requestParams.getFirst(OAuthConstants.AUTHORIZATION_CODE_VALUE);
    ClientAccessToken at = null;
    if (codeParam != null) {
      AuthorizationCodeGrant grant =
          new AuthorizationCodeGrant(codeParam, getAbsoluteRedirectUri(ui));
      grant.setCodeVerifier(state.getFirst(OAuthConstants.AUTHORIZATION_CODE_VERIFIER));
      at = OAuthClientUtils.getAccessToken(accessTokenServiceClient, consumer, grant);
    }
    ClientTokenContext tokenContext = initializeClientTokenContext(rc, at, state);
    if (at != null && clientTokenContextManager != null) {
      clientTokenContextManager.setClientTokenContext(mc, tokenContext);
    }
    setClientCodeRequest(tokenContext);
  }