Skip to main content
Version: 7.2405.x.x LTS

REST Authentication

This section explains how to get a token to call the nevisAdmin 4 REST API.

This is an example and not trimmed for security. In a production setup you should adapt the commands to ensure that login credentials are not exposed.

Set the URL of your nevisAdmin 4 instance:

export NEVISADMIN_URL=http://localhost:9080

Provide login credentials:

export ADMIN_USER=admin
export ADMIN_PASSWORD=admin

Login:

# for HTTPS, you can add the -k flag to curl commands to skip certificate verification
export AUTH_RESPONSE=$(curl -v -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -d "{\"userKey\":\"${ADMIN_USER}\",\"password\":\"${ADMIN_PASSWORD}\"}" "$NEVISADMIN_URL/nevisadmin/api/v1/login?tokenType=bearer")

Extract token from response:

export TOKEN=$(echo $AUTH_RESPONSE | sed -nE 's/.*"token" : "(.*)" }/\1/p')

You can reuse the exported variables for further requests. We recommend to unset at least the login credentials:

unset ADMIN_USER
unset ADMIN_PASSWORD