From 8e3bf97821b7057920286aca16c649e48f3275a1 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Mon, 22 Jul 2013 17:17:01 +0100 Subject: [PATCH] Fix problem with migration - OAuth --- mediagoblin/db/migrations.py | 14 ++++++++------ mediagoblin/federation/forms.py | 1 - mediagoblin/federation/oauth.py | 4 +--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py index 015dbff0..374ab4c8 100644 --- a/mediagoblin/db/migrations.py +++ b/mediagoblin/db/migrations.py @@ -25,6 +25,8 @@ from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.sql import and_ from migrate.changeset.constraint import UniqueConstraint + +from mediagoblin.db.extratypes import JSONEncoded from mediagoblin.db.migration_tools import RegisterMigration, inspect_table from mediagoblin.db.models import MediaEntry, Collection, User, MediaComment @@ -382,7 +384,7 @@ def pw_hash_nullable(db): # oauth1 migrations -class Client_v0(Base): +class Client_v0(declarative_base()): """ Model representing a client - Used for API Auth """ @@ -407,7 +409,7 @@ class Client_v0(Base): else: return "".format(self.id) -class RequestToken_v0(Base): +class RequestToken_v0(declarative_base()): """ Model for representing the request tokens """ @@ -415,7 +417,7 @@ class RequestToken_v0(Base): token = Column(Unicode, primary_key=True) secret = Column(Unicode, nullable=False) - client = Column(Unicode, ForeignKey(Client.id)) + client = Column(Unicode, ForeignKey(Client_v0.id)) user = Column(Integer, ForeignKey(User.id), nullable=True) used = Column(Boolean, default=False) authenticated = Column(Boolean, default=False) @@ -424,7 +426,7 @@ class RequestToken_v0(Base): created = Column(DateTime, nullable=False, default=datetime.datetime.now) updated = Column(DateTime, nullable=False, default=datetime.datetime.now) -class AccessToken_v0(Base): +class AccessToken_v0(declarative_base()): """ Model for representing the access tokens """ @@ -433,12 +435,12 @@ class AccessToken_v0(Base): token = Column(Unicode, nullable=False, primary_key=True) secret = Column(Unicode, nullable=False) user = Column(Integer, ForeignKey(User.id)) - request_token = Column(Unicode, ForeignKey(RequestToken.token)) + request_token = Column(Unicode, ForeignKey(RequestToken_v0.token)) created = Column(DateTime, nullable=False, default=datetime.datetime.now) updated = Column(DateTime, nullable=False, default=datetime.datetime.now) -class NonceTimestamp_v0(Base): +class NonceTimestamp_v0(declarative_base()): """ A place the timestamp and nonce can be stored - this is for OAuth1 """ diff --git a/mediagoblin/federation/forms.py b/mediagoblin/federation/forms.py index 39d6fc27..94c7cb52 100644 --- a/mediagoblin/federation/forms.py +++ b/mediagoblin/federation/forms.py @@ -1,5 +1,4 @@ import wtforms -from mediagoblin.tools.translate import lazy_pass_to_ugettext as _ class AuthorizeForm(wtforms.Form): """ Form used to authorize the request token """ diff --git a/mediagoblin/federation/oauth.py b/mediagoblin/federation/oauth.py index 764b8535..8229c47d 100644 --- a/mediagoblin/federation/oauth.py +++ b/mediagoblin/federation/oauth.py @@ -15,8 +15,7 @@ # along with this program. If not, see . from oauthlib.common import Request -from oauthlib.oauth1 import (AuthorizationEndpoint, RequestValidator, - RequestTokenEndpoint, AccessTokenEndpoint) +from oauthlib.oauth1 import RequestValidator from mediagoblin.db.models import NonceTimestamp, Client, RequestToken, AccessToken @@ -110,7 +109,6 @@ class GMGRequestValidator(RequestValidator): return client.secret def get_access_token_secret(self, client_key, token, request): - client = Client.query.filter_by(id=client_key).first() access_token = AccessToken.query.filter_by(token=token).first() return access_token.secret -- 2.25.1