use enhancer
This commit is contained in:
parent
1572605706
commit
5dedba216f
|
@ -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.set("duration", "permanent");
|
||||
System.out.println("===== at enhancer point ===");
|
||||
authorizationRequestEnhancer.enhance(request, resource, form, headers);
|
||||
final AccessTokenRequest copy = request;
|
||||
|
||||
|
@ -192,6 +193,7 @@ public class MyAuthorizationCodeAccessTokenProvider extends AuthorizationCodeAcc
|
|||
requestParameters.put("response_type", "code");
|
||||
requestParameters.put("client_id", resource.getClientId());
|
||||
requestParameters.put("duration", "permanent");
|
||||
System.out.println("===== at private message redirect ===");
|
||||
|
||||
String redirectUri = resource.getRedirectUri(request);
|
||||
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.AccessTokenProviderChain;
|
||||
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.implicit.ImplicitAccessTokenProvider;
|
||||
import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordAccessTokenProvider;
|
||||
|
@ -93,8 +94,9 @@ public class WebConfig extends WebMvcConfigurerAdapter {
|
|||
@Bean
|
||||
public OAuth2RestTemplate redditRestTemplate(OAuth2ClientContext clientContext) {
|
||||
OAuth2RestTemplate template = new OAuth2RestTemplate(reddit(), clientContext);
|
||||
AccessTokenProvider accessTokenProvider = new AccessTokenProviderChain(Arrays.<AccessTokenProvider> asList(new MyAuthorizationCodeAccessTokenProvider(), new ImplicitAccessTokenProvider(), new ResourceOwnerPasswordAccessTokenProvider(),
|
||||
new ClientCredentialsAccessTokenProvider()));
|
||||
AuthorizationCodeAccessTokenProvider authProvider = new AuthorizationCodeAccessTokenProvider();
|
||||
authProvider.setAuthorizationRequestEnhancer(new CustomRequestEnhancer());
|
||||
AccessTokenProvider accessTokenProvider = new AccessTokenProviderChain(Arrays.<AccessTokenProvider> asList(authProvider, new ImplicitAccessTokenProvider(), new ResourceOwnerPasswordAccessTokenProvider(), new ClientCredentialsAccessTokenProvider()));
|
||||
template.setAccessTokenProvider(accessTokenProvider);
|
||||
return template;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue