API Token
Upon faraday v3.9 we included an API Token for our api. The token for the API will expire when the user changes the password.
You can configure token expiration in the [server]
section of the configuration with the option api_token_expiration
expressed in seconds.
Token expires by timeout or when the user changes the password. Each token is associated to the user who requests the token.
This is a example request of how to obtain a token
curl --user USER:PASSWORD http://localhost:5985/_api/v3/token/
"eyJhbGciOiJIUzUxMiIsImlhdCI6MTYxOTAzMTU3OCwiZXhwIjoxNjIxNjIxNzc4fQ.eyJ1c2VyX2lkIjoiZjNjYTUyNjYtOWU2ZS00NzQwLWI0NWItN2Y2M2JkZWMzN2UwIiwidmFsaWRhdGlvbl9jaGVjayI6IiQ1JHJvdW5kcz01MzUwMDAkVDZ3cy9ZMGFHUW10UnEzSSRpRS5OSG1oaDNWR0h4VXIudVpRNGRnaEVVUXFiS09pWGg5VGdrTURtQXIwIn0.gu6AgQ-iIvdnrHBphBfzWopn5B21D_RvTFvltcoMnksAj0eHhfh7dkJW4GfjhZPQd02RBAsb3vvUUCA0fORvfw"
Now that you got the auth token you can start using it on every request to the api:
curl 'http://localhost:5985/_api/v3/ws/' -H 'Authorization:Token AUTH_TOKEN' -H 'Content-Type: application/json'
import requests
session = requests.Session()
user = 'faraday'
password = 'yourpassword'
session.auth = (user, password)
auth = session.post('https://localhost:5985/_api/v3/token')
response = session.get('https://localhost5985/_api/v3/token')
print(response.text) ## now the token is in response