redpanda-data / benthos

MIT License
214 stars 61 forks source link

Issue-2448: Support OAuth 2.0 with bootstrapped refresh token #71

Closed nregati closed 2 months ago

nregati commented 3 months ago

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 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.

CLAassistant commented 3 months ago

CLA assistant check
All committers have signed the CLA.