Skip to content
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

feat: renew expired access token #112

Merged
merged 2 commits into from
Feb 26, 2021
Merged

feat: renew expired access token #112

merged 2 commits into from
Feb 26, 2021

Conversation

jfatta
Copy link
Contributor

@jfatta jfatta commented Feb 26, 2021

  • During setup (common initialization process for all commands), check if the access token is expired (according to the configuration property stored during login.)
  • In that case, trigger the same login flow (with minor changes on the messages displayed to the user)
  • Then move on with the requested command.

This way the user can login as part of the experience of the requested command instead of failing.

2021-02-26 15 25 44

@Widcket
Copy link
Contributor

Widcket commented Feb 26, 2021

@jfatta :shipit:

@jfatta
Copy link
Contributor Author

jfatta commented Feb 26, 2021

@jfatta :shipit:

thanks. I'm adding a unit test for IsExpired() 😅

@@ -21,7 +22,8 @@ import (
)

const (
userAgent = "Auth0 CLI"
userAgent = "Auth0 CLI"
accessTokenExpThreshold = 5 // minutes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about doing 5 * time.Minute here and in the caller below doing int(accessTokenExpThreshold.Minutes()) ?

Copy link
Contributor Author

@jfatta jfatta Feb 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! I always mess with it because time.* feels invalid for constants to me (which is not the case)

Copy link
Contributor

@cyx cyx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just a small idea on the expiration representation of int vs time.Duration

@jfatta jfatta merged commit a9a932f into main Feb 26, 2021
@jfatta jfatta deleted the feat-renew-token branch February 26, 2021 19:06
@woloski
Copy link

woloski commented Feb 27, 2021

did you implement refresh token? using rt you can get a new at. No need for user interaction. You need to add scope offline_access for that

@cyx
Copy link
Contributor

cyx commented Feb 27, 2021

We were (me mostly) being paranoid that refresh tokens can last for super long. If we can scope those to a month max maybe it's fine?

@woloski
Copy link

woloski commented Feb 27, 2021 via email

@jfatta
Copy link
Contributor Author

jfatta commented Mar 1, 2021

@woloski @cyx if we agree that storing the refresh token on the config file is OK (given that asking permissions for macOS keychain might be inappropriate and not cross-platform), I can update this to:

  • login stores AT and RT at config
  • (every command setup) if AT is expired, get a new one with the RT
  • if the previous step failed for some reason, trigger the login flow as today

makes sense?

@woloski
Copy link

woloski commented Mar 1, 2021 via email

@jfatta
Copy link
Contributor Author

jfatta commented Mar 1, 2021

@woloski yes, we can do that (we used a similar pkg for one of our internal projects too: https://github.com/99designs/keyring/).

My question was more related to the fact that accessing the keychain requires explicit user consent (a dialog appears the first time and with each new binary/updated), are we ok with this?

(I'll iterate on the solutions discussed here later this week)

@woloski
Copy link

woloski commented Mar 1, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants