[feature] OAuth access token refresh
As a User
I want OAuth token refreshed automatically
So that I run my workflows continuously when authenticated via OAuth
Acceptance Criteria TODO
Definition of Done TODO
#1099
@ivicac regarding to
Add locking on connectionId level when refreshing tokens to avoid concurrency issues when the same connection wants to refresh token multiple times at the same time
What triggers refresh is usually regular executePerform or executeOptions or executePerformPolyglot call. To avoid parallel refresh, executeOptions and executePolyglot should not be allowed to call in parallel.
Should we do re-entrant synchronization on connection name if there is ComponentConnection immediately in perform/performPolyglot/options calls?
Why I ask... If we synchronize only call to refresh method, we would end up with two sequential calls where call 2 might invalidate refreshed token in previous call.
@igorbeslic I would extend the connection table with two oauth specific columns:
- oauth_access_token_last_refreshed_date - holds the last refreshed date
- expires_in - number in milliseconds, which tells how long an access token is valid
expires_in is optional. If set, it can be found in the connectionParameters map. If it is not present, we can use 1 min as the default value.
Then, refresk token logic should be locked by ReEntrantLock using connectionId as a scope. After locking every time, we should calculate from the above two values if we need to refresh the token or if the token is valid and there is no need to refresh it.
The main reason is that multiple requests can be made simultaneously that require token refresh, and only the first is enough to perform the refresh.