'Generic method for fetching an access token from the token endpoint.
If you are using the MobileApplicationClient you will want to use
token_from_fragment instead of fetch_token.
:param token_url: Token endpoint URL, must use HTTPS.
:param code: Authorization code (used by WebApplicationClients).
:param authorization_response: Authorization response URL, the callback
URL of the request back to you. Used by
WebApplicationClients instead of code.
:param body: Optional application/x-www-form-urlencoded body to add the
include in the token request. Prefer kwargs over body.
:param auth: An auth tuple or method as accepted by requests.
:param username: Username used by LegacyApplicationClients.
:param password: Password used by LegacyApplicationClients.
:param method: The HTTP method used to make the request. Defaults
to POST, but may also be GET. Other methods should
be added as needed.
:param headers: Dict to default request headers with.
:param timeout: Timeout of the request in seconds.
:param verify: Verify SSL certificate.
:param kwargs: Extra parameters to include in the token request.
:return: A token dict'

def fetch_token(self, token_url, code=None, authorization_response=None, body=u'', auth=None, username=None, password=None, method=u'POST', timeout=None, headers=None, verify=True, **kwargs):

    if (not is_secure_transport(token_url)):
        raise InsecureTransportError()
    if ((not code) and authorization_response):
        self._client.parse_request_uri_response(authorization_response, state=self._state)
        code = self._client.code
    elif ((not code) and isinstance(self._client, WebApplicationClient)):
        code = self._client.code
        if (not code):
            raise ValueError(u'Please    supply    either    code    or    authorization_code    parameters.')
    body = self._client.prepare_request_body(code=code, body=body, redirect_uri=self.redirect_uri, username=username, password=password, **kwargs)
    if ((not auth) and username):
        if (password is None):
            raise ValueError(u'Username    was    supplied,    but    not    password.')
        auth = requests.auth.HTTPBasicAuth(username, password)
    headers = (headers or {u'Accept': u'application/json', u'Content-Type': u'application/x-www-form-urlencoded;charset=UTF-8'})
    self.token = {}
    if (method.upper() == u'POST'):
        r = self.post(token_url, data=dict(urldecode(body)), timeout=timeout, headers=headers, auth=auth, verify=verify)
        log.debug(u'Prepared    fetch    token    request    body    %s', body)
    elif (method.upper() == u'GET'):
        r = self.get(token_url, params=dict(urldecode(body)), timeout=timeout, headers=headers, auth=auth, verify=verify)
        log.debug(u'Prepared    fetch    token    request    querystring    %s', body)
    else:
        raise ValueError(u'The    method    kwarg    must    be    POST    or    GET.')
    log.debug(u'Request    to    fetch    token    completed    with    status    %s.', r.status_code)
    log.debug(u'Request    headers    were    %s', r.request.headers)
    log.debug(u'Request    body    was    %s', r.request.body)
    log.debug(u'Response    headers    were    %s    and    content    %s.', r.headers, r.text)
    log.debug(u'Invoking    %d    token    response    hooks.', len(self.compliance_hook[u'access_token_response']))
    for hook in self.compliance_hook[u'access_token_response']:
        log.debug(u'Invoking    hook    %s.', hook)
        r = hook(r)
    self._client.parse_request_body_response(r.text, scope=self.scope)
    self.token = self._client.token
    log.debug(u'Obtained    token    %s.', self.token)
    return self.token
