IndominusByte / fastapi-jwt-auth

FastAPI extension that provides JWT Auth support (secure, easy to use, and lightweight)
http://indominusbyte.github.io/fastapi-jwt-auth/
MIT License
630 stars 143 forks source link

set token durability #44

Closed silvanohirtie closed 3 years ago

silvanohirtie commented 3 years ago

How can I set how much a token lasts? For now, I can use one just for a couple of minutes, 10 or maybe 20, but then it gets unavailable.

brunohenriquy commented 3 years ago

How can I set how much a token lasts? For now, I can use one just for a couple of minutes, 10 or maybe 20, but then it gets unavailable.

https://indominusbyte.github.io/fastapi-jwt-auth/configuration/general/


authjwt_access_token_expires
How long an access token should live before it expires. This takes value integer (seconds) or datetime.timedelta, and defaults to 15 minutes. Can be set to False to disable expiration.

authjwt_refresh_token_expires
How long an refresh token should live before it expires. This takes value integer (seconds) or datetime.timedelta, and defaults to 30 days. Can be set to False to disable expiration.
silvanohirtie commented 3 years ago

@brunohenriquy an example on how to use it? I need to define it when I create the token or like it's a setting i can define at the top of the file? I'm creating the jwt like this: access_token = Authorize.create_access_token(subject="testUser")

brunohenriquy commented 3 years ago

@brunohenriquy an example on how to use it? I need to define it when I create the token or like it's a setting i can define at the top of the file? I'm creating the jwt like this: access_token = Authorize.create_access_token(subject="testUser")

It's a setting, if you are using a single file only for trying the lib, check this example here: https://indominusbyte.github.io/fastapi-jwt-auth/usage/basic/

You can do:


class Settings(BaseModel):
    authjwt_secret_key: str = "secret"
    authjwt_access_token_expires = 1800 # It's in seconds, so it will be 30 minutes
    authjwt_refresh_token_expires = 86400 # It's in seconds, so it will be 24 hours
silvanohirtie commented 3 years ago

oh clear now, thanks!!