Skip to content

Instantly share code, notes, and snippets.

@cuongld2
Created March 16, 2020 09:28
Show Gist options
  • Save cuongld2/50a2b4b743cfc63604fc54f01b7f5c56 to your computer and use it in GitHub Desktop.
Save cuongld2/50a2b4b743cfc63604fc54f01b7f5c56 to your computer and use it in GitHub Desktop.
create access token
def create_access_token(*, data: dict, expires_delta: timedelta = None):
secret_key = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7"
algorithm = "HS256"
to_encode = data.copy()
if expires_delta:
expire = datetime.utcnow() + expires_delta
else:
expire = datetime.utcnow() + timedelta(minutes=15)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(to_encode, secret_key, algorithm=algorithm)
return encoded_jwt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment