'Pass user access token from Django app to ELasticsearch

Im developing a django app that requires users to authenticate via azure ad (Oauth2). The app also interacts with an elasticsearch service that requires the same oauth2 authentication.

during development I have used a static username and password to login like this:

user_name = "elastic"
host_ip = "127.0.0.1"
host_ports = 9200

elk_url = f'https://{user_name}:{ESPASSWORD}@{host_ip}:{host_ports}'

ELASTICSEARCH_DSL = {
    'default': {
        'hosts': elk_url,
        'ca_certs': False,
        'verify_certs': False,
    }
}

How can I pass the users token to the elasticsearch service?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source