import requests
import json


def get_token_data(oauth_service, token):
    """
    Gets the OAuth2 user attributes using the supplied token
    :param OAuthSSHCertSigningService oauth_service: an
        OAuthSSHCertSigningService object
    :param basestring token: an OAuth2 token
    :return: a json object of user attributes
    :rtype: dict
    """
    if token is None:
        return
    # Verify=False is a bad thing, but I need it for now
    r = requests.get(
        oauth_service.oauth_check_token_url, {
            'token': token
        },
        verify=False)
    decoded_token = json.loads(r.text)
    if 'error' in decoded_token:
        return
    return decoded_token