<commit_before>from social_core.backends.oauth import BaseOAuth2


class AtlassianOAuth2(BaseOAuth2):
    name = 'atlassian'
    AUTHORIZATION_URL = 'https://accounts.atlassian.com/authorize'
    ACCESS_TOKEN_METHOD = 'POST'
    ACCESS_TOKEN_URL = 'https://api.atlassian.com/oauth/token'
    DEFAULT_SCOPE = ['read:jira-user', 'offline_access']
    ID_KEY = 'accountId'
    EXTRA_DATA = [
        ('cloud_id', 'cloud_id'),
        ('refresh_token', 'refresh_token'),
        ('expires_in', 'expires_in'),
    ]

    def auth_params(self, state=None):
        params = super(AtlassianOAuth2, self).auth_params(state)
        params.update({'audience': 'api.atlassian.com',
                       'prompt': 'consent'})
        return params

    def get_user_details(self, response):
        fullname, first_name, last_name = self.get_user_names(response['displayName'])
        return {'username': response['name'],
                'email': response['emailAddress'],
                'fullname': fullname,
                'first_name': first_name,
                'last_name': last_name}

    def user_data(self, access_token, *args, **kwargs):
        clouds = self.get_json('https://api.atlassian.com/oauth/token/accessible-resources',
                               headers={'Authorization': 'Bearer {}'.format(access_token)})
        cloud_id = clouds[0]['id']
        user_info = self.get_json('https://api.atlassian.com/ex/jira/{}/rest/api/2/myself'.format(cloud_id),
                                  headers={'Authorization': 'Bearer {}'.format(access_token)})
        user_info['cloud_id'] = cloud_id
        return user_info<commit_msg>Store all cloud ids<commit_after>from social_core.backends.oauth import BaseOAuth2


class AtlassianOAuth2(BaseOAuth2):
    name = 'atlassian'
    AUTHORIZATION_URL = 'https://accounts.atlassian.com/authorize'
    ACCESS_TOKEN_METHOD = 'POST'
    ACCESS_TOKEN_URL = 'https://api.atlassian.com/oauth/token'
    DEFAULT_SCOPE = ['read:jira-user', 'offline_access']
    ID_KEY = 'accountId'
    EXTRA_DATA = [
        ('cloud_id', 'cloud_id'),
        ('refresh_token', 'refresh_token'),
        ('expires_in', 'expires_in'),
    ]

    def auth_params(self, state=None):
        params = super(AtlassianOAuth2, self).auth_params(state)
        params.update({'audience': 'api.atlassian.com',
                       'prompt': 'consent'})
        return params

    def get_user_details(self, response):
        fullname, first_name, last_name = self.get_user_names(response['displayName'])
        return {'username': response['name'],
                'email': response['emailAddress'],
                'fullname': fullname,
                'first_name': first_name,
                'last_name': last_name}

    def user_data(self, access_token, *args, **kwargs):
        resources = self.get_json('https://api.atlassian.com/oauth/token/accessible-resources',
                                  headers={'Authorization': 'Bearer {}'.format(access_token)})
        resource_ids = [resource['id'] for resource in resources]
        user_info = self.get_json('https://api.atlassian.com/ex/jira/{}/rest/api/2/myself'.format(resource_ids[0]),
                                  headers={'Authorization': 'Bearer {}'.format(access_token)})
        user_info['resource_ids'] = resource_ids
        return user_info
{'fraction_non_alphanumeric': 0.13986849970113568, 'fraction_numerical': 0.0035863717872086074, 'mean_word_length': 2.764904386951631, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '344300', 'n_tokens_mistral': 1053, 'n_tokens_neox': 1026, 'n_words': 160}