source: documentViewer/AuthTokenGenerator.py @ 520:8c5aae9bdbbb

Last change on this file since 520:8c5aae9bdbbb was 520:8c5aae9bdbbb, checked in by casties, 12 years ago

new token generator for Annotator backend (doesn't work yet).

File size: 991 bytes
Line 
1from OFS.SimpleItem import SimpleItem
2
3import datetime
4import hashlib
5
6
7ZERO = datetime.timedelta(0)
8class 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
17UTC = Utc()
18
19
20class 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.