def add_access_token(self, client_id, user_id, access_lifetime,
                         refresh_token=None, refresh_lifetime=None,
                         expires_refresh=None, the_scope=None):
        
        now = datetime.datetime.now()

        # do -> while FTW
        access_token = MongoStorage.generate_hash_512()
        while self.get_access_token(access_token):
            access_token = MongoStorage.generate_hash_512()

        expires_access = add_seconds_to_date(now, access_lifetime)

        # It guarantees uniqueness. Better way?
        if not refresh_token:
            # do -> while FTW
            refresh_token = MongoStorage.generate_hash_512()
            while self.get_refresh_token(refresh_token):
                refresh_token = MongoStorage.generate_hash_512()
            
            expires_refresh = add_seconds_to_date(now, refresh_lifetime)

        self.db.tokens.save({'_id': refresh_token,
                             'client_id': client_id,
                             'user_id': user_id,
                             'expires_access': expires_access,
                             'expires_refresh': expires_refresh,
                             'the_scope': the_scope,
                             'access_token': access_token})

        return access_token, refresh_token, expires_access
Generates an access token and adds it to the database. If the refresh
dataset/ETHPy150Open joaoqalves/web2py-oauth2/modules/oauth/storage/__init__.py/MongoStorage.add_access_token