This file is indexed.

/usr/share/pyshared/social_auth/backends/contrib/evernote.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"""
EverNote OAuth support

No extra configurations are needed to make this work.
"""
from urllib2 import HTTPError
try:
    from urlparse import parse_qs
    parse_qs  # placate pyflakes
except ImportError:
    # fall back for Python 2.5
    from cgi import parse_qs

from oauth2 import Token
from social_auth.utils import setting
from social_auth.backends import ConsumerBasedOAuth, OAuthBackend
from social_auth.exceptions import AuthCanceled


if setting('EVERNOTE_DEBUG', False):
    EVERNOTE_SERVER = 'sandbox.evernote.com'
else:
    EVERNOTE_SERVER = 'www.evernote.com'

EVERNOTE_REQUEST_TOKEN_URL = 'https://%s/oauth' % EVERNOTE_SERVER
EVERNOTE_ACCESS_TOKEN_URL = 'https://%s/oauth' % EVERNOTE_SERVER
EVERNOTE_AUTHORIZATION_URL = 'https://%s/OAuth.action' % EVERNOTE_SERVER


class EvernoteBackend(OAuthBackend):
    """
    Evernote OAuth authentication backend.

    Possible Values:
       {'edam_expires': ['1367525289541'],
        'edam_noteStoreUrl': [
            'https://sandbox.evernote.com/shard/s1/notestore'
        ],
        'edam_shard': ['s1'],
        'edam_userId': ['123841'],
        'edam_webApiUrlPrefix': ['https://sandbox.evernote.com/shard/s1/'],
        'oauth_token': [
            'S=s1:U=1e3c1:E=13e66dbee45:C=1370f2ac245:P=185:A=my_user:' \
            'H=411443c5e8b20f8718ed382a19d4ae38'
        ]}
    """
    name = 'evernote'

    EXTRA_DATA = [
        ('access_token', 'access_token'),
        ('oauth_token', 'oauth_token'),
        ('edam_noteStoreUrl', 'store_url'),
        ('edam_expires', 'expires')
    ]

    @classmethod
    def extra_data(cls, user, uid, response, details=None):
        data = super(EvernoteBackend, cls).extra_data(user, uid, response, details)
        # Evernote returns expiration timestamp in miliseconds, so it needs to
        # be normalized.
        if 'expires' in data:
            data['expires'] = unicode(int(data['expires']) / 1000)
        return data

    def get_user_details(self, response):
        """Return user details from Evernote account"""
        return {
            'username': response['edam_userId'],
            'email': '',
        }

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


class EvernoteAuth(ConsumerBasedOAuth):
    """Evernote OAuth authentication mechanism"""
    AUTHORIZATION_URL = EVERNOTE_AUTHORIZATION_URL
    REQUEST_TOKEN_URL = EVERNOTE_REQUEST_TOKEN_URL
    ACCESS_TOKEN_URL = EVERNOTE_ACCESS_TOKEN_URL
    AUTH_BACKEND = EvernoteBackend
    SETTINGS_KEY_NAME = 'EVERNOTE_CONSUMER_KEY'
    SETTINGS_SECRET_NAME = 'EVERNOTE_CONSUMER_SECRET'

    def access_token(self, token):
        """Return request for access token value"""
        request = self.oauth_request(token, self.ACCESS_TOKEN_URL)

        try:
            response = self.fetch_response(request)
        except HTTPError, e:
            # Evernote returns a 401 error when AuthCanceled
            if e.code == 401:
                raise AuthCanceled(self)
            else:
                raise

        params = parse_qs(response)

        # evernote sents a empty secret token, this way it doesn't fires up the
        # exception
        response = response.replace('oauth_token_secret=',
                                    'oauth_token_secret=None')
        token = Token.from_string(response)

        token.user_info = params
        return token

    def user_data(self, access_token, *args, **kwargs):
        """Return user data provided"""
        # drop lists
        return dict([(key, val[0]) for key, val in
            access_token.user_info.items()])


# Backend definition
BACKENDS = {
    'evernote': EvernoteAuth,
}