use of io.gravitee.rest.api.service.impl.configuration.application.registration.client.register.ClientRegistrationResponse in project gravitee-management-rest-api by gravitee-io.
the class ClientRegistrationServiceImpl method renewClientSecret.
@Override
public ClientRegistrationResponse renewClientSecret(String previousRegistrationResponse) {
try {
ClientRegistrationResponse registrationResponse = mapper.readValue(previousRegistrationResponse, ClientRegistrationResponse.class);
if (registrationResponse.getRegistrationAccessToken() == null || registrationResponse.getRegistrationAccessToken().isEmpty() || registrationResponse.getRegistrationClientUri() == null || registrationResponse.getRegistrationClientUri().isEmpty()) {
throw new RegisteredClientNotUpdatableException();
}
Set<ClientRegistrationProviderEntity> providers = findAll();
if (providers == null || providers.isEmpty()) {
throw new MissingDynamicClientRegistrationProviderException();
}
// For now, take the first provider
ClientRegistrationProviderEntity provider = providers.iterator().next();
// Get provider client
DynamicClientRegistrationProviderClient registrationProviderClient = getDCRClient(false, provider);
String renewClientSecretEndpoint = provider.getRenewClientSecretEndpoint();
TemplateEngine templateEngine = TemplateEngine.templateEngine();
templateEngine.getTemplateContext().setVariable("client_id", registrationResponse.getClientId());
if (registrationProviderClient instanceof DiscoveryBasedDynamicClientRegistrationProviderClient) {
((DiscoveryBasedDynamicClientRegistrationProviderClient) registrationProviderClient).getMetadata().forEach((s, o) -> templateEngine.getTemplateContext().setVariable(s, o));
}
return registrationProviderClient.renewClientSecret(provider.getRenewClientSecretMethod(), templateEngine.getValue(renewClientSecretEndpoint, String.class), registrationResponse.getRegistrationAccessToken());
} catch (IOException ioe) {
LOGGER.error("Unexpected error while updating a client", ioe);
return null;
}
}
Aggregations