This file is indexed.

/usr/share/pyshared/social_auth/backends/contrib/yammer.py is in python-django-social-auth 0.7.23-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"""
Yammer OAuth2 support
"""
import logging
from urllib import urlencode
from urlparse import parse_qs

from django.utils import simplejson
from django.utils.datastructures import MergeDict

from social_auth.backends import BaseOAuth2, OAuthBackend
from social_auth.exceptions import AuthCanceled
from social_auth.utils import dsa_urlopen, setting


YAMMER_SERVER = 'yammer.com'
YAMMER_STAGING_SERVER = 'staging.yammer.com'
YAMMER_OAUTH_URL = 'https://www.%s/oauth2/' % YAMMER_SERVER
YAMMER_AUTH_URL = 'https://www.%s/dialog/oauth' % YAMMER_SERVER
YAMMER_API_URL = 'https://www.%s/api/v1/' % YAMMER_SERVER


class YammerBackend(OAuthBackend):
    name = 'yammer'
    EXTRA_DATA = [
        ('id', 'id'),
        ('expires', 'expires'),
        ('mugshot_url', 'mugshot_url')
    ]

    def get_user_id(self, details, response):
        return response['user']['id']

    def get_user_details(self, response):
        username = response['user']['name']
        first_name = response['user']['first_name']
        last_name = response['user']['last_name']
        full_name = response['user']['full_name']
        email = response['user']['contact']['email_addresses'][0]['address']
        mugshot_url = response['user']['mugshot_url']
        return {
            'username': username,
            'email': email,
            'fullname': full_name,
            'first_name': first_name,
            'last_name': last_name,
            'picture_url': mugshot_url
        }


class YammerOAuth2(BaseOAuth2):
    AUTH_BACKEND = YammerBackend
    AUTHORIZATION_URL = YAMMER_AUTH_URL
    ACCESS_TOKEN_URL = '%s%s' % (YAMMER_OAUTH_URL, 'access_token')
    REQUEST_TOKEN_URL = '%s%s' % (YAMMER_OAUTH_URL, 'request_token')
    SETTINGS_KEY_NAME = 'YAMMER_CONSUMER_KEY'
    SETTINGS_SECRET_NAME = 'YAMMER_CONSUMER_SECRET'

    def user_data(self, access_token, *args, **kwargs):
        """Load user data from yammer"""
        params = {
            'client_id': setting(self.SETTINGS_KEY_NAME, ''),
            'client_secret': setting(self.SETTINGS_SECRET_NAME, ''),
            'code': access_token
        }

        url = '%s?%s' % (self.ACCESS_TOKEN_URL, urlencode(params))

        try:
            return simplejson.load(dsa_urlopen(url))
        except Exception, e:
            logging.exception(e)
        return None

    def auth_complete(self, *args, **kwargs):
        """Yammer API is a little strange"""
        if 'error' in self.data:
            logging.error("%s: %s:\n%s" % (
                self.data('error'), self.data('error_reason'),
                self.data('error_description')
            ))
            raise AuthCanceled(self)

        # now we need to clean up the data params
        data = dict(self.data.copy())
        redirect_state = data.get('redirect_state')
        if redirect_state and '?' in redirect_state:
            redirect_state, extra = redirect_state.split('?', 1)
            extra = parse_qs(extra)
            data['redirect_state'] = redirect_state
            if 'code' in extra:
                data['code'] = extra['code'][0]
        self.data = MergeDict(data)
        return super(YammerOAuth2, self).auth_complete(*args, **kwargs)


BACKENDS = {
    'yammer': YammerOAuth2
}