Skip to main content

Authentication

POST /api/login

Acquire proper authorization for other API requests.

After a successful authentication, the obtained cookie session can be used for other API requests. GET permission is granted for read-only user access, while GET and POST permissions are granted for read-write user access.

The session is similar to that used in Web Admin Access and governed by the same session idle timeout. For more persistent API access, consider authorization with Client ID / Secret.

Available in 7.0.0 or later

Input Parameters

FieldTypeRequiredDescription
usernamestringUsername
passwordstringPassword

Response

Permission Object:

FieldTypeDescription
GETnumber1 = allow retrieving data, 0 = not allowed
POSTnumber1 = allow changing settings, 0 = not allowed

cURL Example

curl -c cookies.txt -H "Content-Type: application/json" \
-X POST -d '{"username":"user","password":"pass"}' \
http://192.168.1.1/api/login
{
"stat": "ok",
"response": {
"permission": {
"GET": 1,
"POST": 1
}
}
}

POST /api/logout

Properly logout the current session. It is advised to logout immediately after use.

Available in 7.0.0 or later

cURL Example

curl -b cookies.txt -H "Content-Type: application/json" \
-X POST http://192.168.1.1/api/logout
{
"stat": "ok"
}

GET /api/auth.client

Get the authentication client list. Only Admin Permission can access this information.

Available in 7.1.1 or later

Response

Returns an array of Client objects:

FieldTypeDescription
namestringName of the client
clientIdstring (hash)Client ID for granting the access token
clientSecretstring (hash)Client Secret for granting the access token
confidentialbooleanConfidential or public client type
createTimestampintegerCreate timestamp of the client
scopestringapi or api.read-only

cURL Example

curl -b cookies.txt http://192.168.1.1/api/auth.client
{
"stat": "ok",
"response": [
{
"name": "Client 1",
"clientId": "9270c250111cabab02058007bb72217e",
"clientSecret": "cf5fe1c51252a058ebd6bd7d5f493cf5",
"confidential": false,
"createTimestamp": 32172904,
"scope": "api.read-only"
}
]
}

POST /api/auth.client

Create or remove a client. Only Admin Permission can access this information.

Available in 7.1.1 or later

Create a Client

Input Parameters

FieldTypeRequiredDescription
actionstringadd
namestringClient name
scopestringapi (read-write) or api.read-only (read-only)

Response

Returns the created Client object (same fields as GET response).

cURL Example

curl -b cookies.txt -H "Content-Type: application/json" \
-X POST -d '{"action":"add","name":"Client 2","scope":"api"}' \
http://192.168.1.1/api/auth.client
{
"stat": "ok",
"response": {
"name": "Client 2",
"clientId": "0396c250111dcaef02058007bb72217e",
"clientSecret": "de5cd1c51252a13854d6bd7ddeabbcf5",
"confidential": false,
"createTimestamp": 32175831,
"scope": "api"
}
}

Remove a Client

Input Parameters

FieldTypeRequiredDescription
actionstringremove
clientIdstring (hash)Client ID to remove

cURL Example

curl -b cookies.txt -H "Content-Type: application/json" \
-X POST -d '{"action":"remove","clientId":"0396c250111dcaef02058007bb72217e"}' \
http://192.168.1.1/api/auth.client
{
"stat": "ok"
}

GET /api/auth.client.token

Obtain the access token list by providing the client ID. Only Admin Permission can access this information.

Available in 7.1.1 or later

Input Parameters

FieldTypeRequiredDescription
clientIdstring (hash)optionalClient ID. If absent, all access tokens will be returned.

Response

Returns an array of Access_Token objects:

FieldTypeDescription
accessTokenstring (hash)Access token
clientIdstring (hash)Client ID
clientNamestringClient Name
authorizationTypenumberAlways 3 (client credentials grant)
scopestringapi or api.read-only
createTimestampintegerIssued date in timestamp

cURL Example

curl -b cookies.txt \
"http://192.168.1.1/api/auth.client.token?clientId=0396c250111dcaef02058007bb72217e"
{
"stat": "ok",
"response": [
{
"accessToken": "43c65216eb16d779092fc40b184a1794",
"clientId": "0396c250111dcaef02058007bb72217e",
"clientName": "Client 1",
"authorizationType": 3,
"scope": "api.read-only",
"createTimestamp": 32177831
}
]
}

POST /api/auth.token.grant

Generate a new access token by giving the clientId and clientSecret.

Available in 7.1.1 or later

Input Parameters

FieldTypeRequiredDescription
clientIdstring (hash)Client ID
clientSecretstring (hash)Client Secret
scopestringoptionalapi (read-write) or api.read-only (read-only)

Response

FieldTypeDescription
accessTokenstring (hash)Access token
authorizationTypenumberAlways 3 (client credentials grant)
scopestringapi or api.read-only
expiresInintegerExpires in seconds

Using the Access Token

Add the access token as a GET parameter:

GET /api/status.wan.connection?accessToken=43c65216eb16d779092fc40b184a1794 HTTP/1.1
Host: 192.168.1.1

cURL Example

curl -b cookies.txt -H "Content-Type: application/json" \
-X POST -d '{"clientId":"0396c250111dcaef02058007bb72217e","clientSecret":"de5cd1c51252a13854d6bd7ddeabbcf5","scope":"api"}' \
http://192.168.1.1/api/auth.token.grant
{
"stat": "ok",
"response": {
"accessToken": "43c65216eb16d779092fc40b184a1794",
"authorizationType": 3,
"scope": "api",
"expiresIn": 172800
}
}

POST /api/auth.token.revoke

Revoke the access token provided. Only Admin Permission or self-revoke can access this.

Available in 7.1.1 or later

Input Parameters

FieldTypeRequiredDescription
accessTokenstring (hash)Access token to revoke

cURL Example

curl -b cookies.txt -H "Content-Type: application/json" \
-X POST -d '{"accessToken":"0396c250111dcaef02058007bb72217e"}' \
http://192.168.1.1/api/auth.token.revoke
{
"stat": "ok"
}