Skip to content
This repository has been archived by the owner on May 31, 2022. It is now read-only.

Custom token name in RemoteTokenServices #297

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -12,10 +12,6 @@
*******************************************************************************/
package org.springframework.security.oauth2.provider.token;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.http.HttpEntity;
Expand All @@ -35,6 +31,10 @@
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Map;

/**
* Queries the /check_token endpoint to obtain the contents of an access token.
*
Expand All @@ -56,6 +56,8 @@ public class RemoteTokenServices implements ResourceServerTokenServices {

private String clientSecret;

private String tokenName;

private AccessTokenConverter tokenConverter = new DefaultAccessTokenConverter();

public RemoteTokenServices() {
Expand Down Expand Up @@ -91,11 +93,15 @@ public void setAccessTokenConverter(AccessTokenConverter accessTokenConverter) {
this.tokenConverter = accessTokenConverter;
}

@Override
public void setTokenName(String tokenName) {
this.tokenName = tokenName;
}

@Override
public OAuth2Authentication loadAuthentication(String accessToken) throws AuthenticationException, InvalidTokenException {

MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
formData.add("token", accessToken);
formData.add(tokenName, accessToken);
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", getAuthorizationHeader(clientId, clientSecret));
Map<String, Object> map = postForMap(checkTokenEndpointUrl, formData, headers);
Expand Down