Mercurial > hg > documentViewer
changeset 520:8c5aae9bdbbb
new token generator for Annotator backend (doesn't work yet).
author | casties |
---|---|
date | Thu, 15 Mar 2012 10:20:24 +0100 |
parents | 9a3cc3732194 |
children | 112578de1470 |
files | AuthTokenGenerator.py |
diffstat | 1 files changed, 39 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AuthTokenGenerator.py Thu Mar 15 10:20:24 2012 +0100 @@ -0,0 +1,39 @@ +from OFS.SimpleItem import SimpleItem + +import datetime +import hashlib + + +ZERO = datetime.timedelta(0) +class Utc(datetime.tzinfo): + def utcoffset(self, dt): + return ZERO + + def tzname(self, dt): + return "UTC" + + def dst(self, dt): + return ZERO +UTC = Utc() + + +class AuthTokenGenerator(SimpleItem): + """Generator of auth tokens for OKFN Annotator""" + # Replace these with your details + consumerKey = 'yourconsumerkey' + consumerSecret = 'yourconsumersecret' + + # Only change this if you're sure you know what you're doing + CONSUMER_TTL = 86400 + + def generate_token(self, user_id): + issue_time = datetime.datetime.now(UTC).isoformat() + token = hashlib.sha256(self.consumerSecret + user_id + issue_time).hexdigest() + + return dict( + consumerKey=self.consumerKey, + authToken=token, + authTokenIssueTime=issue_time, + authTokenTTL=CONSUMER_TTL, + userId=user_id + )