Class OAuth2AccessTokenInterceptor

java.lang.Object
org.springframework.cloud.openfeign.security.OAuth2AccessTokenInterceptor
All Implemented Interfaces:
feign.RequestInterceptor

public class OAuth2AccessTokenInterceptor extends Object implements feign.RequestInterceptor
A RequestInterceptor for OAuth2 Feign Requests. By default, it uses the OAuth2AuthorizedClientManager to get OAuth2AuthorizedClient that holds an OAuth2AccessToken. If the user has specified an OAuth2 clientRegistrationId using the feign.oauth2.clientRegistrationId property, it will be used to retrieve the token. If the token is not retrieved or the clientRegistrationId has not been specified, the serviceId retrieved from the url host segment will be used. This approach is convenient for load-balanced Feign clients. For non-load-balanced ones, the property-based clientRegistrationId is a suitable approach.
Since:
4.0.0
Author:
Dangzhicairang(小水牛), Olga Maciaszek-Sharma
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The name of the header.
    static final String
    The name of the token.
  • Constructor Summary

    Constructors
    Constructor
    Description
    OAuth2AccessTokenInterceptor(String tokenType, String header, String clientRegistrationId, org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager oAuth2AuthorizedClientManager)
     
    OAuth2AccessTokenInterceptor(String clientRegistrationId, org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager oAuth2AuthorizedClientManager)
     
    OAuth2AccessTokenInterceptor(org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager oAuth2AuthorizedClientManager)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    apply(feign.RequestTemplate template)
     
    org.springframework.security.oauth2.core.OAuth2AccessToken
    getToken(feign.RequestTemplate template)
     
    protected org.springframework.security.oauth2.core.OAuth2AccessToken
    getToken(String clientRegistrationId)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • OAuth2AccessTokenInterceptor

      public OAuth2AccessTokenInterceptor(org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager oAuth2AuthorizedClientManager)
    • OAuth2AccessTokenInterceptor

      public OAuth2AccessTokenInterceptor(String clientRegistrationId, org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager oAuth2AuthorizedClientManager)
    • OAuth2AccessTokenInterceptor

      public OAuth2AccessTokenInterceptor(String tokenType, String header, String clientRegistrationId, org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager oAuth2AuthorizedClientManager)
  • Method Details

    • apply

      public void apply(feign.RequestTemplate template)
      Specified by:
      apply in interface feign.RequestInterceptor
    • getToken

      public org.springframework.security.oauth2.core.OAuth2AccessToken getToken(feign.RequestTemplate template)
    • getToken

      protected org.springframework.security.oauth2.core.OAuth2AccessToken getToken(String clientRegistrationId)