commit
c6d8560590
|
@ -0,0 +1,22 @@
|
||||||
|
package org.baeldung.config;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails;
|
||||||
|
import org.springframework.security.oauth2.client.token.AccessTokenRequest;
|
||||||
|
import org.springframework.security.oauth2.client.token.RequestEnhancer;
|
||||||
|
import org.springframework.util.MultiValueMap;
|
||||||
|
|
||||||
|
public class CustomRequestEnhancer implements RequestEnhancer, Serializable {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enhance(AccessTokenRequest request, OAuth2ProtectedResourceDetails resource, MultiValueMap<String, String> form, HttpHeaders headers) {
|
||||||
|
System.out.println("called===");
|
||||||
|
form.set("duration", "permanent");
|
||||||
|
}
|
||||||
|
}
|
|
@ -56,6 +56,7 @@ public class MyAuthorizationCodeAccessTokenProvider extends AuthorizationCodeAcc
|
||||||
form.putAll(getParametersForAuthorizeRequest(resource, request));
|
form.putAll(getParametersForAuthorizeRequest(resource, request));
|
||||||
}
|
}
|
||||||
form.set("duration", "permanent");
|
form.set("duration", "permanent");
|
||||||
|
System.out.println("===== at enhancer point ===");
|
||||||
authorizationRequestEnhancer.enhance(request, resource, form, headers);
|
authorizationRequestEnhancer.enhance(request, resource, form, headers);
|
||||||
final AccessTokenRequest copy = request;
|
final AccessTokenRequest copy = request;
|
||||||
|
|
||||||
|
@ -192,6 +193,7 @@ public class MyAuthorizationCodeAccessTokenProvider extends AuthorizationCodeAcc
|
||||||
requestParameters.put("response_type", "code");
|
requestParameters.put("response_type", "code");
|
||||||
requestParameters.put("client_id", resource.getClientId());
|
requestParameters.put("client_id", resource.getClientId());
|
||||||
requestParameters.put("duration", "permanent");
|
requestParameters.put("duration", "permanent");
|
||||||
|
System.out.println("===== at private message redirect ===");
|
||||||
|
|
||||||
String redirectUri = resource.getRedirectUri(request);
|
String redirectUri = resource.getRedirectUri(request);
|
||||||
if (redirectUri != null) {
|
if (redirectUri != null) {
|
||||||
|
|
|
@ -15,6 +15,7 @@ import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResour
|
||||||
import org.springframework.security.oauth2.client.token.AccessTokenProvider;
|
import org.springframework.security.oauth2.client.token.AccessTokenProvider;
|
||||||
import org.springframework.security.oauth2.client.token.AccessTokenProviderChain;
|
import org.springframework.security.oauth2.client.token.AccessTokenProviderChain;
|
||||||
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider;
|
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider;
|
||||||
|
import org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeAccessTokenProvider;
|
||||||
import org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails;
|
import org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails;
|
||||||
import org.springframework.security.oauth2.client.token.grant.implicit.ImplicitAccessTokenProvider;
|
import org.springframework.security.oauth2.client.token.grant.implicit.ImplicitAccessTokenProvider;
|
||||||
import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordAccessTokenProvider;
|
import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordAccessTokenProvider;
|
||||||
|
@ -93,8 +94,9 @@ public class WebConfig extends WebMvcConfigurerAdapter {
|
||||||
@Bean
|
@Bean
|
||||||
public OAuth2RestTemplate redditRestTemplate(OAuth2ClientContext clientContext) {
|
public OAuth2RestTemplate redditRestTemplate(OAuth2ClientContext clientContext) {
|
||||||
OAuth2RestTemplate template = new OAuth2RestTemplate(reddit(), clientContext);
|
OAuth2RestTemplate template = new OAuth2RestTemplate(reddit(), clientContext);
|
||||||
AccessTokenProvider accessTokenProvider = new AccessTokenProviderChain(Arrays.<AccessTokenProvider> asList(new MyAuthorizationCodeAccessTokenProvider(), new ImplicitAccessTokenProvider(), new ResourceOwnerPasswordAccessTokenProvider(),
|
AuthorizationCodeAccessTokenProvider authProvider = new AuthorizationCodeAccessTokenProvider();
|
||||||
new ClientCredentialsAccessTokenProvider()));
|
authProvider.setAuthorizationRequestEnhancer(new CustomRequestEnhancer());
|
||||||
|
AccessTokenProvider accessTokenProvider = new AccessTokenProviderChain(Arrays.<AccessTokenProvider> asList(authProvider, new ImplicitAccessTokenProvider(), new ResourceOwnerPasswordAccessTokenProvider(), new ClientCredentialsAccessTokenProvider()));
|
||||||
template.setAccessTokenProvider(accessTokenProvider);
|
template.setAccessTokenProvider(accessTokenProvider);
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue