16 Mart 2020 Pazartesi

SpringSecurity OAuth2RestTemplate Sınıfı

constructor
Şöyle yaparız.
ClientCredentialsResourceDetails oauthDetails = new ClientCredentialsResourceDetails();
oauthDetails.setClientId("test");
oauthDetails.setClientSecret("test");
oauthDetails.setAccessTokenUri("https://test/auth/oauth/token");
oauthDetails.setGrantType("client_credentials");

List<String> scopes = new ArrayList<>();
scopes.add("read");
oauthDetails.setScope(scopes);

new OAuth2RestTemplate(oauthDetails);
exchange metodu
Şöyle yaparız.
try {
  return oAuth2RestTemplate.exchange(url, HttpMethod.GET, entity, Resource.class);
} catch (OAuth2AccessDeniedException ex) {
  ...
} catch (HttpClientErrorException ex) {
  ...
} catch (PolarisClientConfigurationException ex) {
  ...
}

Hiç yorum yok:

Yorum Gönder