]> git.openstreetmap.org Git - osqa.git/blob - forum_modules/oauthauth/authentication.py
Merge pull request #5 from lra/french
[osqa.git] / forum_modules / oauthauth / authentication.py
1 import json
2
3 from consumer import OAuthAbstractAuthConsumer
4 from forum.authentication.base import ConsumerTemplateContext
5
6 from lib import oauth2
7 import settings
8
9 class TwitterAuthConsumer(OAuthAbstractAuthConsumer):
10     def __init__(self):
11         OAuthAbstractAuthConsumer.__init__(self,
12                 str(settings.TWITTER_CONSUMER_KEY),
13                 str(settings.TWITTER_CONSUMER_SECRET),
14                 "twitter.com",
15                 "https://api.twitter.com/oauth/request_token",
16                 "https://api.twitter.com/oauth/access_token",
17                 "https://api.twitter.com/oauth/authorize",
18         )
19
20     def get_user_data(self, key):
21         json = self.fetch_data(key, "https://twitter.com/account/verify_credentials.json")
22         
23         if 'screen_name' in json:
24             creds = json.loads(json)
25
26             return {
27                 'username': creds['screen_name']
28             }
29         
30         
31         return {}
32
33 class TwitterAuthContext(ConsumerTemplateContext):
34     mode = 'BIGICON'
35     type = 'DIRECT'
36     weight = 150
37     human_name = 'Twitter'
38     icon = '/media/images/openid/twitter.png'