bytechef icon indicating copy to clipboard operation
bytechef copied to clipboard

[feature] OAuth access token refresh

Open ivicac opened this issue 1 year ago • 1 comments

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

ivicac avatar Mar 20 '24 05:03 ivicac

#1099

igorbeslic avatar May 22 '24 16:05 igorbeslic

@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 avatar Jun 13 '24 17:06 igorbeslic

@igorbeslic I would extend the connection table with two oauth specific columns:

  1. oauth_access_token_last_refreshed_date - holds the last refreshed date
  2. 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.

ivicac avatar Jun 19 '24 12:06 ivicac