0

I am using eve's set_mongo_prefix() hook within a custom authentication class which works well.

class ServerTokenAuth(TokenAuth):
    def check_auth(self, token, allowed_roles, resource, method):
        tokens = app.data.driver.db['owner_token_mapping']
        mapping = tokens.find_one({'token': token})
        if mapping is not None and token == mapping['token']:
            add_db_to_config(app, mapping['slug'])
            self.set_mongo_prefix(mapping['slug'])
            return True
        return False

My question is, how do I tell eve's db driver to set_mongo_prefix? The work around is to use requests to re-authenticate, which is really not ideal.

cheers.

rick
  • 163
  • 4
  • do you read the https://stackoverflow.com/questions/49354474/can-i-dynamically-create-db-instances-for-use-with-mongo-prefix – Brown Bear Aug 21 '18 at 09:12
  • yes @BearBrown that is exactly what I am doing, and it works as advertised. It's more when I want to do some custom logic inside Eve without having to pass the end users token to the http end-point via the requests library – rick Aug 21 '18 at 20:42

0 Answers0