API authentication
Some P4 Search API endpoints need an authenticated connection. Authenticated connections are achieved using Token authentication or Bearer authentication.
Token authentication
Token authentication is an HTTP authentication system that uses an X-Auth-Token to authenticate the connection to P4 Search. The X-Auth-Token is generated by the server in response to a log in request. The generated X-Auth-Token is automatically added to the P4 Search config.properties file under the com.perforce.p4search.service.token configurable. See Index auth-token.
For example:
curl -H 'X-Auth-Token: <X-AUTH-TOKEN>' http://localhost:1601/api/v1.2/index/change/917503
Bearer authentication
Bearer authentication is an HTTP authentication system that uses a bearer token to authenticate the connection to P4 Search. The bearer token is generated by the server in response to a log in request. The bearer token is sent in the authorization header when you make an API request.
For example:
Obtain the bearer token by logging in to your P4 Search instance:
curl --location --request POST 'http://localhost:1601/api/v1/login' --header 'Content-Type: application/json' --data-raw '{ "user": "<p4user>", "passwd": "<p4password>", "ip": "<ipaddress>" }'
Where <ipaddress> is the machine where the ticket will be generated.
P4 Search responds with the bearer token:
{ "status": { "code": 200, "message": "OK" }, "data": "<auth_token>" }
To make an API request using the bearer token:
curl -X GET --location "http://localhost:1601/api/v1.2/install/extensions" -H "Authorization: Bearer <auth_token>" -H "Accept: application/json"