'Get token for OAuth temporary code
This is the last step of OAuth login.
Should be called in OAuth Callback handler.
Args:
code (str): oauth code for finishing OAuth login
Returns:
token (str): JupyterHub API Token'

def token_for_code(self, code):

    params = dict(client_id=self.oauth_client_id, client_secret=self.api_token, grant_type='authorization_code', code=code, redirect_uri=self.oauth_redirect_uri)
    token_reply = self._api_request('POST', self.oauth_token_url, data=urlencode(params).encode('utf8'), headers={'Content-Type': 'application/x-www-form-urlencoded'})
    return token_reply['access_token']
