class BaseCredentialProvider implements CredentialProvider {

    protected static String callbackUrlFor(final URI baseUrl, final MultiValueMap<String, String> additionalParams) {
        final String path = baseUrl.getPath();

        final String callbackPath = path + "credentials/callback";

        try {
            final URI base = new URI(baseUrl.getScheme(), null, baseUrl.getHost(), baseUrl.getPort(), callbackPath,
                null, null);

            return UriComponentsBuilder.fromUri(base).queryParams(additionalParams).build().toUriString();
        } catch (final URISyntaxException e) {
            throw new IllegalStateException("Unable to generate callback URI", e);
        }
    }

}