Authentication
Every API request can either include an Authorization header or not.
If the header is missing, the request is executed with the permissions of the anonymous user - see the configuration for the ANONYMOUS_USER_UUID environment variable that controls which user that is.
The Authorization header carries a bearer token, e.g.:
Authorization: Bearer secret-token:M3WHIDj4q62EY0XiZFMLnvHow to get a token
Tokens can be created in three ways:
- Through the endpoint.
- Through the CLI command.
- Tokens without an expiration date can be created by removing the
expirationDateproperty from a token object directly in the Neo4j database or in a backup file.
Discouraged in production
Creating tokens without an expiration date by editing the database directly is highly discouraged for any production system - prefer the endpoint or the CLI command, which both issue tokens with a proper lifetime.
Example
curl \ -H 'Content-Type: application/json' \ -d '{ "type": "Token", "uniqueUserIdentifier": "test@localhost.dev", "password": "1234" }' \ https://api.example.com/tokenResponse:
{ "type": "_TokenResponse", "token": "secret-token:M3WHIDj4q62EY0XiZFMLnv"}The value of $.token is the new bearer token, ready to be sent in the Authorization header of subsequent requests. See first API for a full walkthrough.
Tokens have a limited lifetime and must be recreated once they expire; see the token.* settings in the configuration reference for the configurable minimum, default and maximum lifetimes. A user may hold an unlimited number of active tokens at the same time.
Tokens with capabilities
Most requests only need an ordinary token like the one above. Some instance-wide functionality, e.g. changing or assigning roles, is protected by capabilities, which a user gets through their roles. A token has no capabilities by default, even if the user has them; request the ones you need in capabilities when you create the token:
curl \ -H 'Content-Type: application/json' \ -d '{ "type": "Token", "uniqueUserIdentifier": "test@localhost.dev", "password": "1234", "capabilities": [ "schema.manage" ] }' \ https://api.example.com/tokenThe response looks like the one above. Capabilities which the user does not have are refused with 403 Forbidden. See roles and for the available capabilities and roles.