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: implement refresh_token API #938

Merged
merged 2 commits into from
Dec 4, 2023

Conversation

darknight
Copy link
Contributor

@darknight darknight commented Dec 2, 2023

follow up of #912

Changes include:

  • use uuid without hyphen as refresh token
  • refresh token expires in 7 days by default
  • create refresh_tokens table, add r/w operations
  • implement refresh_token logic
  • update register API, since it's new user, we always generate new refresh token and return it
  • update token_auth API, first we check if there exists valid (unexpired) refresh token for current user, if not, generate new one

Pending task:

  • implemement revoke_token

    • this can be done by updating expires_in field, invalidate current token.
  • To clean up expired refresh tokens, there are two options:

    1. do clean up during login (i.e. token_auth), if no valid refresh token, we generate new one, meanwhile, delete all expired ones.
    2. spawn a background task when server starts, run clean up periodically

@wsxiaoys what's your suggestion?

@wsxiaoys
Copy link
Member

wsxiaoys commented Dec 2, 2023

spawn a background task when server starts, run clean up periodically

I'll suggest go with this approach, example:
https://github.com/TabbyML/tabby/blob/main/crates/tabby-scheduler/src/lib.rs#L11

The tokio job can be spawned when creating db conn.

Copy link
Member

@wsxiaoys wsxiaoys left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM

ee/tabby-webserver/src/service/db.rs Outdated Show resolved Hide resolved
ee/tabby-webserver/src/service/db.rs Outdated Show resolved Hide resolved
@darknight darknight force-pushed the i805-refresh-token branch 2 times, most recently from 563168e to bf0c828 Compare December 3, 2023 14:00
Copy link
Member

@wsxiaoys wsxiaoys left a comment

Choose a reason for hiding this comment

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

Please also:

  1. Resolve conflicts.
  2. Update schema file (if needed)

ee/tabby-webserver/src/service/db_job.rs Outdated Show resolved Hide resolved
@wsxiaoys wsxiaoys merged commit 73442c3 into TabbyML:main Dec 4, 2023
3 checks passed
@darknight darknight deleted the i805-refresh-token branch December 4, 2023 05:30
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.

2 participants