Example usage for org.springframework.security.oauth2.client.token OAuth2AccessTokenSupport setTokenRequestEnhancer

List of usage examples for org.springframework.security.oauth2.client.token OAuth2AccessTokenSupport setTokenRequestEnhancer

Introduction

In this page you can find the example usage for org.springframework.security.oauth2.client.token OAuth2AccessTokenSupport setTokenRequestEnhancer.

Prototype

public void setTokenRequestEnhancer(RequestEnhancer tokenRequestEnhancer) 

Source Link

Document

A custom enhancer for the access token request

Usage

From source file:org.cloudfoundry.identity.client.UaaContextFactory.java

/**
 * Adds a request enhancer to the provider.
 * Currently only two request parameters are being enhanced
 * 1. If the {@link TokenRequest} wants an id_token the <code>id_token token</code> values are added as a response_type parameter
 * 2. If the {@link TokenRequest} is a {@link org.cloudfoundry.identity.client.token.GrantType#PASSWORD_WITH_PASSCODE}
 * the <code>passcode</code> parameter will be added to the request
 * @param tokenRequest the token request, expected to be a password grant
 * @param provider the provider to enhance
 *//*from   w ww .  j  a va2s.  c  o  m*/
protected void enhanceRequestParameters(TokenRequest tokenRequest, OAuth2AccessTokenSupport provider) {
    provider.setTokenRequestEnhancer( //add id_token to the response type if requested.
            (AccessTokenRequest request, OAuth2ProtectedResourceDetails resource,
                    MultiValueMap<String, String> form, HttpHeaders headers) -> {
                if (tokenRequest.wantsIdToken()) {
                    form.put(OAuth2Utils.RESPONSE_TYPE, Arrays.asList("id_token token"));
                }
                if (tokenRequest.getGrantType() == PASSWORD_WITH_PASSCODE) {
                    form.put("passcode", Arrays.asList(tokenRequest.getPasscode()));
                }
            });
}