public class OAuth2FeignRequestInterceptor extends Object implements feign.RequestInterceptor
OAuth2ClientContext
provided from the environment and
construct a new header on the request before it is made by FeignModifier and Type | Field and Description |
---|---|
static String |
AUTHORIZATION |
static String |
BEARER |
Constructor and Description |
---|
OAuth2FeignRequestInterceptor(org.springframework.security.oauth2.client.OAuth2ClientContext oAuth2ClientContext,
org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails resource)
Default constructor which uses the provided OAuth2ClientContext and Bearer tokens
within Authorization header
|
OAuth2FeignRequestInterceptor(org.springframework.security.oauth2.client.OAuth2ClientContext oAuth2ClientContext,
org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails resource,
String tokenType,
String header)
Fully customizable constructor for changing token type and header name, in cases of
Bearer and Authorization is not the default such as "bearer", "authorization"
|
Modifier and Type | Method and Description |
---|---|
protected org.springframework.security.oauth2.common.OAuth2AccessToken |
acquireAccessToken()
Try to acquire the token using a access token provider
|
void |
apply(feign.RequestTemplate template)
Create a template with the header of provided name and extracted extract
|
protected String |
extract(String tokenType)
Extracts the token extract id the access token exists or returning an empty extract
if there is no one on the context it may occasionally causes Unauthorized response
since the token extract is empty
|
org.springframework.security.oauth2.common.OAuth2AccessToken |
getToken()
Extract the access token within the request or try to acquire a new one by
delegating it to
acquireAccessToken() |
public static final String BEARER
public static final String AUTHORIZATION
public OAuth2FeignRequestInterceptor(org.springframework.security.oauth2.client.OAuth2ClientContext oAuth2ClientContext, org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails resource)
oAuth2ClientContext
- provided contextresource
- type of resource to be accessedpublic OAuth2FeignRequestInterceptor(org.springframework.security.oauth2.client.OAuth2ClientContext oAuth2ClientContext, org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails resource, String tokenType, String header)
oAuth2ClientContext
- current oAuth2 Contextresource
- type of resource to be accessedtokenType
- type of token e.g. "token", "Bearer"header
- name of the header e.g. "Authorization", "authorization"public void apply(feign.RequestTemplate template)
apply
in interface feign.RequestInterceptor
RequestInterceptor.apply(RequestTemplate)
protected String extract(String tokenType)
tokenType
- type name of tokenpublic org.springframework.security.oauth2.common.OAuth2AccessToken getToken()
acquireAccessToken()
protected org.springframework.security.oauth2.common.OAuth2AccessToken acquireAccessToken() throws org.springframework.security.oauth2.client.resource.UserRedirectRequiredException
org.springframework.security.oauth2.client.resource.UserRedirectRequiredException
- in case the user needs to be redirected to an
approval page or login pageCopyright © 2015 Pivotal Software, Inc.. All rights reserved.