Permalink
Browse files

Add Access Token.

  • Loading branch information...
lepture committed Nov 20, 2013
1 parent 679d9a6 commit 88dee8057eb1864d90e1df1895a47efdbad4ee66
Showing with 45 additions and 0 deletions.
  1. +45 −0 app.py
View
45 app.py
@@ -98,6 +98,31 @@ class Nonce(db.Model):
access_token = db.Column(db.String(50))
class AccessToken(db.Model):
id = db.Column(db.Integer, primary_key=True)
client_key = db.Column(
db.String(40), db.ForeignKey('client.client_key'),
nullable=False,
)
client = db.relationship('Client')
user_id = db.Column(
db.Integer, db.ForeignKey('user.id'),
)
user = db.relationship('User')
token = db.Column(db.String(255))
secret = db.Column(db.String(255))
_realms = db.Column(db.Text)
@property
def realms(self):
if self._realms:
return self._realms.split()
return []
def current_user():
if 'id' in session:
uid = session['id']
@@ -205,6 +230,26 @@ def save_nonce(client_key, timestamp, nonce, request_token, access_token):
return nonce
@oauth.tokengetter
def load_access_token(client_key, token, *args, **kwargs):
return AccessToken.query.filter_by(
client_key=client_key, token=token
).first()
@oauth.tokensetter
def save_access_token(token, request):
tok = AccessToken(
client=request.client,
user=request.user,
token=token['oauth_token'],
secret=token['oauth_token_secret'],
_realms=token['oauth_authorized_realms'],
)
db.session.add(tok)
db.session.commit()
if __name__ == '__main__':
db.create_all()
app.run()

0 comments on commit 88dee80

Please sign in to comment.