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