diff options
author | Joar Wandborg <joar@wandborg.se> | 2013-03-10 22:52:07 +0100 |
---|---|---|
committer | Joar Wandborg <joar@wandborg.se> | 2013-04-06 22:17:27 +0200 |
commit | c121a7d3d0c48d4e3abf43c06047dde3e25616c3 (patch) | |
tree | 049194dbcf47d2184845736fca3a75fbdd2cacf9 /mediagoblin/plugins/oauth/migrations.py | |
parent | fe6755f0f44e1148e2cb72538f8e64c4a9740f7f (diff) | |
download | mediagoblin-c121a7d3d0c48d4e3abf43c06047dde3e25616c3.tar.lz mediagoblin-c121a7d3d0c48d4e3abf43c06047dde3e25616c3.tar.xz mediagoblin-c121a7d3d0c48d4e3abf43c06047dde3e25616c3.zip |
OAuth: Support refresh tokens, etc
Initially I was going to write a failing test for refresh tokens. Thus
this fix includes an orphaned 'expect_failure' method in test utils.
I ended up writing support for OAuth refresh tokens, as well as a lot of
cleanup (hopefully) in the OAuth plugin code.
**Rebase**: While waiting for this stuff to be merged, the testing
framework changed, it comes with batteries included regarding fails.
Removed legacy nosetest helper.
Also added a lot of backref=backref([...], cascade='all, delete-orphan')
Diffstat (limited to 'mediagoblin/plugins/oauth/migrations.py')
-rw-r--r-- | mediagoblin/plugins/oauth/migrations.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/mediagoblin/plugins/oauth/migrations.py b/mediagoblin/plugins/oauth/migrations.py index 6aa0d7cb..d7b89da3 100644 --- a/mediagoblin/plugins/oauth/migrations.py +++ b/mediagoblin/plugins/oauth/migrations.py @@ -102,6 +102,21 @@ class OAuthCode_v0(declarative_base()): client_id = Column(Integer, ForeignKey(OAuthClient_v0.id), nullable=False) +class OAuthRefreshToken_v0(declarative_base()): + __tablename__ = 'oauth__refresh_tokens' + + id = Column(Integer, primary_key=True) + created = Column(DateTime, nullable=False, + default=datetime.now) + + token = Column(Unicode, index=True) + + user_id = Column(Integer, ForeignKey(User.id), nullable=False) + + # XXX: Is it OK to use OAuthClient_v0.id in this way? + client_id = Column(Integer, ForeignKey(OAuthClient_v0.id), nullable=False) + + @RegisterMigration(1, MIGRATIONS) def remove_and_replace_token_and_code(db): metadata = MetaData(bind=db.bind) @@ -122,3 +137,22 @@ def remove_and_replace_token_and_code(db): OAuthCode_v0.__table__.create(db.bind) db.commit() + + +@RegisterMigration(2, MIGRATIONS) +def remove_refresh_token_field(db): + metadata = MetaData(bind=db.bind) + + token_table = Table('oauth__tokens', metadata, autoload=True, + autoload_with=db.bind) + + refresh_token = token_table.columns['refresh_token'] + + refresh_token.drop() + db.commit() + +@RegisterMigration(3, MIGRATIONS) +def create_refresh_token_table(db): + OAuthRefreshToken_v0.__table__.create(db.bind) + + db.commit() |