forked from fossasia/open-event-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement Refresh Tokens (fossasia#6204)
* feat: Implement blacklisting and fresh token * Reduce expiry for refresh based token
- Loading branch information
1 parent
2753e7a
commit ec03c5a
Showing
7 changed files
with
158 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from sqlalchemy.sql import func as sql_func | ||
|
||
from app.models import db | ||
|
||
|
||
class UserTokenBlackListTime(db.Model): | ||
"""user token blacklist time model class""" | ||
__tablename__ = 'user_token_blacklist_time' | ||
__table_args__ = (db.UniqueConstraint('user_id', name='user_blacklist_time_uc'),) | ||
|
||
id = db.Column(db.Integer, primary_key=True) | ||
created_at = db.Column(db.DateTime(timezone=True), default=sql_func.now(), nullable=False) | ||
blacklisted_at = db.Column(db.DateTime(timezone=True), default=sql_func.now(), nullable=False) | ||
user_id = db.Column(db.Integer, db.ForeignKey('users.id', ondelete='CASCADE'), nullable=False) | ||
user = db.relationship("User", backref="token_blacklist_times", foreign_keys=[user_id]) | ||
|
||
def __init__(self, user_id=None, created_at=None, blacklisted_at=None): | ||
self.user_id = user_id | ||
self.created_at = created_at | ||
self.blacklisted_at = blacklisted_at | ||
|
||
def __str__(self): | ||
return '<TokenBlackListTime User %s blacklisted at %s>' % (self.user, self.blacklisted_at) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...ions/versions/rev-2019-08-03-05:18:10-4925dd5fd720_add_user_token_blacklist_time_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""Add user token blacklist time table | ||
Revision ID: 4925dd5fd720 | ||
Revises: 2504915ffd08 | ||
Create Date: 2019-08-03 05:18:10.804364 | ||
""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
import sqlalchemy_utils | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '4925dd5fd720' | ||
down_revision = '2504915ffd08' | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table('user_token_blacklist_time', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('created_at', sa.DateTime(timezone=True), server_default='now', nullable=False), | ||
sa.Column('blacklisted_at', sa.DateTime(timezone=True), server_default='now', nullable=False), | ||
sa.Column('user_id', sa.Integer(), nullable=False), | ||
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.UniqueConstraint('user_id', name='user_blacklist_time_uc') | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table('user_token_blacklist_time') | ||
# ### end Alembic commands ### |