-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support refresh_token #2721
Comments
I have the same question. Is there a way to have a long authentication between the companion provider and the cloud provider ? What I want to do is ask permissions to the user once, then store the refresh_token and use it further so the user does not need to authenticate every time it wants to upload a file from Dropbox or any storage provider. |
Similar question. Is there a way to use refresh_token? |
@mifi are you able to answer this? |
Hi. As far as I know (from my testing), the user does not receive a new consent dialog every time the access token is expired, but they just need to reauthenticate. I believe this is because they have already allowed the app to access their account so they just need to choose their google account again (and possibly enter password again). You are right that the access token lasts a short time (e.g. less than an hour or so) and this is by design / best practice. And companion does not support refresh tokens, and so the user will have to reauthenticate after the short lived access token has expired. So I consider this a feature request. ImplementationRefreshing the tokenIf we were using Google's official Node.js SDK it would automatically handle refreshing the token:
https://github.com/googleapis/google-api-nodejs-client#handling-refresh-tokens But because we are using a custom HTTP client (purest), we need to either
Storing the updated refresh tokenUpon receiving a refreshed token from google we need to do this:
refresh_token/access_token race conditionNeed to look into possible race condition: If there are multiple simultaneous companion requests that all refresh the tokens at the same time, will that "just work"? (can a single refresh_token be refreshed many times and produce many new valid refresh_tokens and access_tokens? or will only the first refresh call succeed, and the rest of the requests will fail, leading to potentially many failed uploads for the user? I found this:
Possible solutions:
This also needs to be implemented for all the other companion providers. |
yea, it adds another level of complexity, and refresh tokens differ between all the providers. |
Alright. Closing this but may revisited and reopened at some point. |
reconsidering this - maybe we should do the refreshing of the token in the Uppy client - then we don't need to coordinate multiple refreshing the token between companion servers, but instead we could do it in the client, because there's always just one client. We would still have to coordinate this between all ongoing requests and RateLimitQueue. Let's reopen this, because it will effectively prevent any upload sessions longer than about 1 hour. pseudo code: // global
let refreshingTokenPromise;
async function downloadFile() {
try {
if (refreshingTokenPromise) await refreshingTokenPromise;
await get('/companion/files/12345')
} catch (err) {
if (err.status === 401) {
refreshingTokenPromise = put('/companion/authtoken/refresh', { refreshToken: getRefreshToken() })
await refreshingTokenPromise
refreshingTokenPromise = undefined
return downloadFile()
}
throw err;
}
} |
for dropbox and google drive closes #2721
* allow storing multiple tokens inside uppy auth token * de-duplicate uploadRemote by creating a new superclass UploaderPlugin * pull out requestSocketToken from MiniXHRUpload * add class UploaderPlugin * refactor * refactor * refactor/reuse * refactor/make getAuthToken private * fix bug * implement refresh token for dropbox and google drive closes #2721 * fix test * also update auth token cookie when refreshing token * fix build error on node 14 * increase auth token expiry to workaround expiry * Update packages/@uppy/companion-client/src/RequestClient.js Co-authored-by: Antoine du Hamel <[email protected]> * make queueRequestSocketToken private * rename arg * fix lint * log error message * fix s3 * Update packages/@uppy/companion-client/src/Provider.js Co-authored-by: Antoine du Hamel <[email protected]> --------- Co-authored-by: Antoine du Hamel <[email protected]>
* handle google drive refresh token revoked * implement onedrive refresh tokens #2721
Hi, I haven't found any documentation related to the expiration of tokens in a google drive upload scenario. I want to know how often a user is gonna need to consent. Google OAuth gives an acces_token which is short lived and a refresh_token with an expiration of 6 months on production.
I haven't found any reference to refresh tokens inside companion, Does companion use refresh_tokens? If not how does companion handle the expiration of short-lived access_token?
The text was updated successfully, but these errors were encountered: