Hi, I'm currently running into issues trying to generate access token from the OAuth2 in my spring boot application. I'm running into issues specifically spring security. I'm adding the spring-security-oauth2-client dependency into the project but can't be using OAuth2AuthorizedClientManager since we're struck with spring boot version 2.1.x and spring security 5.1.X. Any thoughts?
#Java 8 OAuth2 using spring boot token generation
1 messages · Page 1 of 1 (latest)
<@&1004656351647117403> please have a look, thanks.
Well my first thought is you should really move to 17, the second: https://spring.io/blog/2018/03/06/using-spring-security-5-to-integrate-with-oauth-2-secured-services-such-as-facebook-and-github .
Thanks. Was finally able to get a work around with it.
HttpPost httppost = new HttpPost("url");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("grant_type", "client_credentials"));
nameValuePairs.add(new BasicNameValuePair("client_id", "client-id"));
nameValuePairs.add(new BasicNameValuePair("client_secret", "client-secret"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
CloseableHttpResponse response = httpclient.execute(httppost);
return ResponseEntity.ok(EntityUtils.toString(response.getEntity()));
Detected code, here are some useful tools:
Formatted code
HttpPost httppost = new HttpPost("url");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("grant_type", "client_credentials"));
nameValuePairs.add(new BasicNameValuePair("client_id", "client-id"));
nameValuePairs.add(new BasicNameValuePair("client_secret", "client-secret"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
CloseableHttpResponse response = httpclient.execute(httppost);
return ResponseEntity.ok(EntityUtils.toString(response.getEntity()));