'Fetch a token and associated details from an authorization server.
Returns something like this:
\'access_token\': \'tsbk6pcSPSNffdzEkxVicwf...\',
\'token_type\': \'Bearer\',
\'expires_at\': 123456789,
\'refresh_token\': \'1CtboygBSKA-Ut1e7...\''

@classmethod
def GetToken(cls, session, oauth2_cfg, code, tok_id=None):

    post_data = urlencode([('code', code), ('client_id', oauth2_cfg['client_id']), ('client_secret', oauth2_cfg['client_secret']), ('redirect_uri', cls.RedirectURI(session.config, oauth2_cfg, session.ui.html_variables.get('http_host'))), ('grant_type', 'authorization_code')])
    data = json.loads(cls.URLGet(session, oauth2_cfg['token_url'], data=post_data))
    tok_id = (tok_id or ('%x' % time.time()))
    session.config.oauth.tokens[tok_id] = {}
    tok_info = session.config.oauth.tokens[tok_id]
    tok_info.provider = oauth2_cfg._key
    tok_info.token_type = data['token_type']
    tok_info.access_token = data['access_token']
    tok_info.expires_at = int((time.time() + data['expires_in']))
    tok_info.refresh_token = data['refresh_token']
    if ('oauth' in session.config.sys.debug):
        session.ui.debug(('Fetched    OAuth2    token    for    %s' % tok_id))
    return (tok_id, tok_info)
