

def parse_token_response(body, scope=None):
    'Parse the JSON token response body into a dict.\n\n    The authorization server issues an access token and optional refresh\n    token, and constructs the response by adding the following parameters\n    to the entity body of the HTTP response with a 200 (OK) status code:\n\n    access_token\n            REQUIRED.  The access token issued by the authorization server.\n    token_type\n            REQUIRED.  The type of the token issued as described in\n            `Section 7.1`_.  Value is case insensitive.\n    expires_in\n            RECOMMENDED.  The lifetime in seconds of the access token.  For\n            example, the value "3600" denotes that the access token will\n            expire in one hour from the time the response was generated.\n            If omitted, the authorization server SHOULD provide the\n            expiration time via other means or document the default value.\n    refresh_token\n            OPTIONAL.  The refresh token which can be used to obtain new\n            access tokens using the same authorization grant as described\n            in `Section 6`_.\n    scope\n            OPTIONAL, if identical to the scope requested by the client,\n            otherwise REQUIRED.  The scope of the access token as described\n            by `Section 3.3`_.\n\n    The parameters are included in the entity body of the HTTP response\n    using the "application/json" media type as defined by [`RFC4627`_].  The\n    parameters are serialized into a JSON structure by adding each\n    parameter at the highest structure level.  Parameter names and string\n    values are included as JSON strings.  Numerical values are included\n    as JSON numbers.  The order of parameters does not matter and can\n    vary.\n\n    :param body: The full json encoded response body.\n    :param scope: The scope requested during authorization.\n\n    For example:\n\n    .. code-block:: http\n\n        HTTP/1.1 200 OK\n        Content-Type: application/json\n        Cache-Control: no-store\n        Pragma: no-cache\n\n        {\n            "access_token":"2YotnFZFEjr1zCsicMWpAA",\n            "token_type":"example",\n            "expires_in":3600,\n            "refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA",\n            "example_parameter":"example_value"\n        }\n\n    .. _`Section 7.1`: http://tools.ietf.org/html/rfc6749#section-7.1\n    .. _`Section 6`: http://tools.ietf.org/html/rfc6749#section-6\n    .. _`Section 3.3`: http://tools.ietf.org/html/rfc6749#section-3.3\n    .. _`RFC4627`: http://tools.ietf.org/html/rfc4627\n    '
    try:
        params = json.loads(body)
    except ValueError:
        params = dict(urlparse.parse_qsl(body))
        for key in ('expires_in', 'expires'):
            if (key in params):
                params[key] = int(params[key])
    if ('scope' in params):
        params['scope'] = scope_to_list(params['scope'])
    if ('expires' in params):
        params['expires_in'] = params.pop('expires')
    if ('expires_in' in params):
        params['expires_at'] = (time.time() + int(params['expires_in']))
    params = OAuth2Token(params, old_scope=scope)
    validate_token_parameters(params)
    return params

dataset/ETHPy150Open idan/oauthlib/oauthlib/oauth2/rfc6749/parameters.py parse_token_response/original