03-25-2021 11:54 PM
Hello,
I didn't find anywhere the way to get token from DCNM in REST way.
I tried like this but look is not working, I get always Bad Request. I'm using Basic Authentication with user:password in base 64.
curl -I --insecure --location --request POST 'https://dcnm-name/rest/logon' --header 'Authorization: Basic 12345=='
Where 12345== is username:password in Base64
Is the username the same I use for dcnm login ?
Should I somewhere define a special user for REST authentication
Solved! Go to Solution.
03-26-2021 02:55 AM
Hi,
I just made a similar test and initially it was also not working.
Then I went to the DCNM swagger/API interface and saw that there was another parameter expirationTime which seems mandatory.
It specifies the validity of the token obtained in miliseconds.
https://172.16.11.11/api-docs/
Example:
curl -i --insecure --header 'Authorization: Basic YWRtaW46c3VnMS1wdWxhCg' -H "Content-Type: application/json" -X POST -d "{ expirationTime: 1000 }" 'https://172.16.11.11/rest/logon'
Result:
{"Dcnm-Token":"h1hFTIq++I5Kl9zUqdxatikE5BOUGARvJenr3L6JX8eslcUF9QqMtaXs+z47tOssBvquBAh20mj6LL7PauIzICuoyoTV7pco4QJIuxi3mexF"}
Buona giornata
03-26-2021 03:24 AM
Bingo
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 26 Mar 2021 10:21:46 GMT
Content-Type: application/json
Content-Length: 61
Connection: keep-alive
Cache-Control: no-store
X-Powered-By: Server
X-XSS-Protection: 1; mode=block
Pragma: no-cache
X-FRAME-OPTIONS: SAMEORIGIN
Content-Security-Policy: default-src https:;connect-src https: wss:;font-src https: data:;frame-src data: blob: https:;frame-ancestors https:;img-src https: data:;media-src https:;object-src https:;script-src 'unsafe-inline' 'unsafe-eval' https:;style-src 'unsafe-inline' https:;
X-Content-Type-Options: nosniff
Strict-Transport-Security: max-age=360000
X-Content-Type-Options: nosniff
{"Dcnm-Token":"gtPgZQ6Hp/D4b6o*****??mQmcivkgtq6g+YS+***="}
03-26-2021 02:55 AM
Hi,
I just made a similar test and initially it was also not working.
Then I went to the DCNM swagger/API interface and saw that there was another parameter expirationTime which seems mandatory.
It specifies the validity of the token obtained in miliseconds.
https://172.16.11.11/api-docs/
Example:
curl -i --insecure --header 'Authorization: Basic YWRtaW46c3VnMS1wdWxhCg' -H "Content-Type: application/json" -X POST -d "{ expirationTime: 1000 }" 'https://172.16.11.11/rest/logon'
Result:
{"Dcnm-Token":"h1hFTIq++I5Kl9zUqdxatikE5BOUGARvJenr3L6JX8eslcUF9QqMtaXs+z47tOssBvquBAh20mj6LL7PauIzICuoyoTV7pco4QJIuxi3mexF"}
Buona giornata
03-26-2021 03:24 AM
Bingo
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 26 Mar 2021 10:21:46 GMT
Content-Type: application/json
Content-Length: 61
Connection: keep-alive
Cache-Control: no-store
X-Powered-By: Server
X-XSS-Protection: 1; mode=block
Pragma: no-cache
X-FRAME-OPTIONS: SAMEORIGIN
Content-Security-Policy: default-src https:;connect-src https: wss:;font-src https: data:;frame-src data: blob: https:;frame-ancestors https:;img-src https: data:;media-src https:;object-src https:;script-src 'unsafe-inline' 'unsafe-eval' https:;style-src 'unsafe-inline' https:;
X-Content-Type-Options: nosniff
Strict-Transport-Security: max-age=360000
X-Content-Type-Options: nosniff
{"Dcnm-Token":"gtPgZQ6Hp/D4b6o*****??mQmcivkgtq6g+YS+***="}
03-26-2021 07:10 AM
Now it seams is missing something to use the token for the REST.
curl -i --insecure --header 'Dcnm-Token: gt==token gotted from above====' -H "Content-Type: application/json" -X GET 'https://dcnm-ip/rest/control/fabrics'
HTTP/1.1 401 Unauthorized
Server: nginx
Date: Fri, 26 Mar 2021 14:00:34 GMT
Content-Type: application/json
Content-Length: 24
Connection: keep-alive
Cache-Control: no-store
X-Powered-By: Server
X-XSS-Protection: 1; mode=block
Pragma: no-cache
X-FRAME-OPTIONS: SAMEORIGIN
Content-Security-Policy: default-src https:;connect-src https: wss:;font-src https: data:;frame-src data: blob: https:;frame-ancestors https:;img-src https: data:;media-src https:;object-src https:;script-src 'unsafe-inline' 'unsafe-eval' https:;style-src 'unsafe-inline' https:;
X-Content-Type-Options: nosniff
Strict-Transport-Security: max-age=360000
03-28-2021 02:32 AM
Hi,
I used the following:
1) curl -k -XPOST --header "Authorization: Basic YWRtaW46c3VnMS1wdWxhCg==" -d "{"expirationTime"=300000}" https://172.16.11.11/rest/logon
I had the expirationTime initially set to a too little value and the token was expiring before I could use it in my second request, thus was getting the same error as you were.
I set it now to 300000 miliseconds = 300 seconds = 5 min :).
2) curl -k -XGET --header 'Dcnm-Token: nGwkuuL56MMg2OVTiknz7HicREWXiE9d4tBadbsIWQBOSVEm9h9rcvgYVgePm8UWxwyWIu3RLBuu7WivttEV5ZCCWunJ9tmMSiAzSQuLkBIJ' https://172.16.11.11/rest/control/fabrics
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide