-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refresh FusionAuth token #175
Comments
See also related Slack thread. |
Just moving some thoughts/commentary from team meeting notes docs over to here: One option would be to just make the default tokens last longer (but "ick", for all the usual reasons). Another option would be for the SFTP Service to refresh the FusionAuth token. In that case, refresh tokens would need to be enabled. Would the refresh token then also need to last longer than 12 hours, to allow for really long uploads? (Or can a refresh token be used to get a newer refresh token? That would be kind of suprising if it could, but who knows.) See https://learn.microsoft.com/en-us/linkedin/shared/authentication/programmatic-refresh-tokens - could make them last a long time! See also FusionAuth docs: https://fusionauth.io/docs/v1/tech/apis/jwt |
Access tokens have lifetimes that might end before the user wants to end their authenticated session. Hence, we need to refresh the user access token after an expiry detection. Resolves: #175 Signed-off-by: fenn-cs <[email protected]>
+1 to what @kfogel wrote: the initial OAuth request should ask for a refresh token, and every subsequent API request should examine the expiration time on the access token and, if near to expiry, use the refresh token to get a new access token and a new refresh token. I don't know what the time limits for refresh tokens are configured to be here; that'll be in the FusionAuth configuration, and someone with access can confirm it for you: @cecilia-donnelly for sure, and maybe other staff developers too. In general, refresh tokens can be fairly long lived, on the order of weeks or months; this is safe because using them involves talking to the OAuth authority, which allows for re-validation and for token revocation. For example, if a user account were deleted, or they changed their password, or perhaps if the requesting IP address changed, the authorization server could reject the refresh request. |
Yes @kfogel! Thanks for linking that up. Actually #194 was a futile attempt. My idea was that, by hitting the login endpoint directly, I would be able to ask for a In sftp-service/src/classes/AuthenticationSession.ts Lines 48 to 51 in a9ca457
However, that did not seem to work and I later found in the documentation that we can't modify that behavior via the current login endpoint. https://fusionauth.io/docs/v1/tech/apis/login#request
|
Based on the conversation in #192 it looks like our current login mechanism does not support refresh tokens. That means we have the following two paths to resolution:
Extending the life of a token is not a true fix, as there would still be edge cases where files take longer than the token's length to resolve. Changing the auth flow
|
UPDATE: it looks like it MAY WELL support refresh tokens! We still may want to explore other forms of authentication at some point, but for now we're going to see if we can get refresh tokens working with the current approach. |
I was able to obtain a refresh token via the login API, and then use the standard OAuth token endpoint to exchange it for a new access token. To do so, I needed to both pass in the application ID and ensure the user logging in was registered in the application. Per the login API docs:
At the moment, we are not automatically registering users in the sftp application. FusionAuth was telling us that, but we weren't doing anything with that information:
Setting the application ID is done by adding a key-value pair to the login object; the type definition does not include the key, but does not prevent it, either: diff --git a/src/classes/AuthenticationSession.ts b/src/classes/AuthenticationSession.ts
index 9d43f3b..8b11b50 100644
--- a/src/classes/AuthenticationSession.ts
+++ b/src/classes/AuthenticationSession.ts
@@ -46,6 +47,7 @@ export class AuthenticationSession {
private processPasswordResponse([password]: string[]): void {
this.fusionAuthClient.login({
+ applicationId: 'redacted',
loginId: this.authContext.username,
password,
}).then((clientResponse) => { Renewing the token was a standard OAuth exchange: curl -v \
--request POST \
--url 'https://permanent-dev.fusionauth.io/oauth2/token' \
--header 'content-type: application/x-www-form-urlencoded' \
--data "client_id=$(<client_id)" \
--data "client_secret=$(<client_secret)" \
--data "refresh_token=$(<refresh_token)" \
--data 'grant_type=refresh_token' \
| jq . My next step will be to clean this up into a pull request, perhaps reusing some of the work in #192. |
Ah! This makes sense! Will be good to talk through how to best resolve that. Nice sleuthing! 🎉 |
Thanks for sleuthing (as Dan named it), @jasonaowen ! We discussed the following possible next steps during rclone check-in today. Approach 1: Handle user-app association in
|
More information on approach 1:
|
Access tokens have lifetimes that might end before the user wants to end their authenticated session. Hence, we need to refresh the user access token after an expiry detection. Resolves: #175 Signed-off-by: fenn-cs <[email protected]>
Access tokens have lifetimes that might end before the user wants to end their authenticated session. Hence, we need to refresh the user access token after an expiry detection. Resolves: #175 Signed-off-by: fenn-cs <[email protected]>
Access tokens have lifetimes that might end before the user wants to end their authenticated session. Hence, we need to refresh the user access token after an expiry detection. Resolves: #175 Signed-off-by: fenn-cs <[email protected]>
Access tokens have lifetimes that might end before the user wants to end their authenticated session. Hence, we need to refresh the user access token after an expiry detection. Resolves: #175 Signed-off-by: fenn-cs <[email protected]>
Access tokens have lifetimes that might end before the user wants to end their authenticated session. Hence, we need to refresh the user access token after an expiry detection. Resolves: #175 Signed-off-by: fenn-cs <[email protected]>
Access tokens have lifetimes that might end before the user wants to end their authenticated session. Hence, we need to refresh the user access token after an expiry detection. Resolves: #175 Signed-off-by: fenn-cs <[email protected]>
Access tokens have lifetimes that might end before the user wants to end their authenticated session. Hence, we need to refresh the user access token after an expiry detection. Resolves: #175 Signed-off-by: fenn-cs <[email protected]>
W00t! 🎉 |
When the file uploads would exceed an hour the backend would fail with
Firebase\JWT\ExpiredException
onGET /folder/getWithChildren
Leading to
On the sftp client.
Apparently the FusionAuth token expires after one hour and so it needs to get refreshed.
Sentry : https://permanentorg.sentry.io/issues/3899931004/?environment=dev&project=3663562&query=is%3Aunresolved&referrer=issue-stream&stream_index=0
The text was updated successfully, but these errors were encountered: