Line | |
---|
1 | from OFS.SimpleItem import SimpleItem |
---|
2 | |
---|
3 | import datetime |
---|
4 | import hashlib |
---|
5 | |
---|
6 | |
---|
7 | ZERO = datetime.timedelta(0) |
---|
8 | class Utc(datetime.tzinfo): |
---|
9 | def utcoffset(self, dt): |
---|
10 | return ZERO |
---|
11 | |
---|
12 | def tzname(self, dt): |
---|
13 | return "UTC" |
---|
14 | |
---|
15 | def dst(self, dt): |
---|
16 | return ZERO |
---|
17 | UTC = Utc() |
---|
18 | |
---|
19 | |
---|
20 | class AuthTokenGenerator(SimpleItem): |
---|
21 | """Generator of auth tokens for OKFN Annotator""" |
---|
22 | # Replace these with your details |
---|
23 | consumerKey = 'yourconsumerkey' |
---|
24 | consumerSecret = 'yourconsumersecret' |
---|
25 | |
---|
26 | # Only change this if you're sure you know what you're doing |
---|
27 | CONSUMER_TTL = 86400 |
---|
28 | |
---|
29 | def generate_token(self, user_id): |
---|
30 | issue_time = datetime.datetime.now(UTC).isoformat() |
---|
31 | token = hashlib.sha256(self.consumerSecret + user_id + issue_time).hexdigest() |
---|
32 | |
---|
33 | return dict( |
---|
34 | consumerKey=self.consumerKey, |
---|
35 | authToken=token, |
---|
36 | authTokenIssueTime=issue_time, |
---|
37 | authTokenTTL=CONSUMER_TTL, |
---|
38 | userId=user_id |
---|
39 | ) |
---|
Note: See
TracBrowser
for help on using the repository browser.