forked from spring-projects/spring-security
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
95 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...gframework/security/oauth2/client/endpoint/DefaultOAuth2TokenRequestHeadersConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.springframework.security.oauth2.client.endpoint; | ||
|
||
import org.springframework.core.convert.converter.Converter; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.RequestEntity; | ||
import org.springframework.security.oauth2.client.registration.ClientRegistration; | ||
import org.springframework.security.oauth2.core.ClientAuthenticationMethod; | ||
|
||
import java.net.URLEncoder; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Collections; | ||
|
||
/** | ||
* Default Converter used by the {@link OAuth2AuthorizationCodeGrantRequestEntityConverter} | ||
* that convert from an implementation of an {@link AbstractOAuth2AuthorizationGrantRequest} | ||
* to a {@link RequestEntity} representation of an OAuth 2.0 Access Token Request for the | ||
* specific Authorization Grant. | ||
* | ||
* @since 6.3 | ||
* @see OAuth2ClientCredentialsGrantRequestEntityConverter | ||
* @author Peter Eastham | ||
* @author Joe Grandja | ||
*/ | ||
public class DefaultOAuth2TokenRequestHeadersConverter<T extends AbstractOAuth2AuthorizationGrantRequest> | ||
implements Converter<T, HttpHeaders> { | ||
|
||
private static final HttpHeaders DEFAULT_TOKEN_HEADERS = getDefaultTokenRequestHeaders(); | ||
private boolean encodeClientCredentials = true; | ||
|
||
private static HttpHeaders getDefaultTokenRequestHeaders() { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON_UTF8)); | ||
final MediaType contentType = MediaType.valueOf(MediaType.APPLICATION_FORM_URLENCODED_VALUE + ";charset=UTF-8"); | ||
headers.setContentType(contentType); | ||
return headers; | ||
} | ||
|
||
|
||
@Override | ||
public HttpHeaders convert(T source) { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.addAll(DEFAULT_TOKEN_HEADERS); | ||
ClientRegistration clientRegistration = source.getClientRegistration(); | ||
if (ClientAuthenticationMethod.CLIENT_SECRET_BASIC.equals(clientRegistration.getClientAuthenticationMethod())) { | ||
String clientId = encodeClientCredentials ? | ||
encodeClientCredential(clientRegistration.getClientId()) : clientRegistration.getClientId(); | ||
String clientSecret = encodeClientCredentials ? | ||
encodeClientCredential(clientRegistration.getClientSecret()) : clientRegistration.getClientSecret(); | ||
headers.setBasicAuth(clientId, clientSecret); | ||
} | ||
return headers; | ||
} | ||
|
||
private static String encodeClientCredential(String clientCredential) { | ||
return URLEncoder.encode(clientCredential, StandardCharsets.UTF_8); | ||
} | ||
|
||
public void setEncodeClientCredentials(boolean encodeClientCredentials) { | ||
this.encodeClientCredentials = encodeClientCredentials; | ||
} | ||
} |
78 changes: 0 additions & 78 deletions
78
...framework/security/oauth2/client/endpoint/OAuth2AuthorizationGrantRequestEntityUtils.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters