Skip to content

Add refresh token support for logins#258

Merged
tminusplus merged 21 commits intomainfrom
tszucs/refresh
May 8, 2024
Merged

Add refresh token support for logins#258
tminusplus merged 21 commits intomainfrom
tszucs/refresh

Conversation

@tminusplus
Copy link
Copy Markdown
Contributor

@tminusplus tminusplus commented Sep 26, 2023

What was changed

This adds refresh tokens to tcld by switching to the golang.org/x/oauth2 which supports device codes and refresh tokens.

Other changes in this PR:

  • Noticed that other tests were reading the actual tcld config folder. And would panic if it does not exist. So added NewTestApp which sets the config dir to a temporary directory + other convenience settings.
  • Removed LoginService to reduce coupling in code, so that connection.go can be tested without invoking a login.
  • Removed mocks around LoginService, to ensure the tcld code is exercised in tests.
  • Added making the config directory, if it doesn't exist, in feature.go to avoid nil panics in testing.
  • Removed the Before code in the NewLoginCommand, as nothing was done with the loaded login config.
  • Removed the use of os.RemoveAll, to ensure a bug does not remove directories on a user's computer when the intent was to remove a single file.

Why?

Allows us to shorten token access expiration times.

Checklist

  • Tested logging in and making a request.
  • Tested logging in on an older tcld, updating, and then making a request.
  • Tested logging in on an older tcld, updating, re-logging in, and verified the config is in the new format.
  • Tested waiting for the access token to expire, and then making a request to get a new refresh token.
  • Added unit tests around refresh token support and the use of the golang.org/x/oauth2 library.
  • Tested login flows with refresh tokens disabled server-side.

@tminusplus tminusplus changed the title [draft] Add refresh token support for logins Add refresh token support for logins Oct 26, 2023
@tminusplus tminusplus marked this pull request as ready for review October 26, 2023 23:36
Comment thread app/credentials/oauth/oauth.go
Comment thread app/login.go Outdated
Comment thread app/connection_test.go Outdated
Comment thread app/credentials/oauth/oauth.go
Comment thread app/credentials/header.go
Comment thread go.mod Outdated
@tminusplus tminusplus requested a review from mastermanu December 7, 2023 23:32
@tminusplus tminusplus requested review from mattkim and shakeelrao May 3, 2024 21:33
Copy link
Copy Markdown
Contributor

@shakeelrao shakeelrao left a comment

Choose a reason for hiding this comment

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

🚀

Comment thread app/connection.go
Comment thread app/logout.go
Comment thread app/token_config.go
@tminusplus tminusplus merged commit d558b08 into main May 8, 2024
@tminusplus tminusplus deleted the tszucs/refresh branch May 8, 2024 23:25
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