'Return the access token generated by the authenticating server.
If token is already in the session that one will be used.
Otherwise the token is fetched from the auth server.'

def accessToken(self):

    session = current.session
    token = session.token
    if (token and ('expires' in token)):
        expires = token['expires']
        if ((expires == 0) or (expires > time.time())):
            return token['access_token']
    code = session.code
    if code:
        data = {'client_id': self.client_id, 'client_secret': self.client_secret, 'redirect_uri': self.args['redirect_uri'], 'code': code, 'grant_type': 'authorization_code', 'scope': self.args['scope']}
        open_url = None
        opener = self.__build_url_opener(self.token_url)
        try:
            open_url = opener.open(self.token_url, urllib.urlencode(data))
        except urllib2.HTTPError as e:
            raise Exception(e.read())
        finally:
            del session.code
        if open_url:
            try:
                token = json.loads(open_url.read())
                token['expires'] = (int(token['expires_in']) + time.time())
            finally:
                opener.close()
            session.token = token
            return token['access_token']
    session.token = None
    return None
