Today, there's no support for refresh tokens in the OAuth 2.0 flow of Benthos http clients.
For continuous running clients fetching data from respective endpoints, it is recommended that refresh tokens be used to renew access tokens if provided as part of the configuration.
This change incorporates the same and uses tokenRefresher TokenSource from Golang’s OAuth2 package instead of the clientcredentials package.
The code checks if the grant_type in the EndpointParams map is set to "refresh_token". If it is, it creates an oauth2.Config with the provided ClientKey, ClientSecret, TokenURL, and Scopes along with oauth2.Token and sets the RefreshToken field with the provided refresh_token in the EndpointParams.
Note: If the refresh token value is missing and the grant_type is set to refresh_token, the flow throws oauth2: token expired and refresh token is not set error.
If the grant_type is not "refresh_token", the method follows the usual clientcredentials flow.
Issue-2448
Today, there's no support for refresh tokens in the OAuth 2.0 flow of Benthos http clients. For continuous running clients fetching data from respective endpoints, it is recommended that refresh tokens be used to renew access tokens if provided as part of the configuration.
This change incorporates the same and uses
tokenRefresher
TokenSource from Golang’s OAuth2 package instead of theclientcredentials
package.The code checks if the
grant_type
in the EndpointParams map is set to"refresh_token"
. If it is, it creates an oauth2.Config with the provided ClientKey, ClientSecret, TokenURL, and Scopes along with oauth2.Token and sets the RefreshToken field with the providedrefresh_token
in the EndpointParams.Note: If the refresh token value is missing and the grant_type is set to refresh_token, the flow throws
oauth2: token expired and refresh token is not set error
.If the grant_type is not "refresh_token", the method follows the usual
clientcredentials
flow.