SOLVED Authenticate on FOG API
I’am trying to use the FOG API. I found some doc here : https://news.fogproject.org/simplified-api-documentation/. Is it the last version ?
Following instructions I tried to get system status by typing the command :
$ curl -i -H 'fog-api-token: <token>' -u fog:password fog-master/fog/system/status
The API is enabled in the UI. I also tried with the “fog-user-token” but nothing works, I always get:
HTTP/1.1 401 Unauthorized Date: Wed, 18 Mar 2020 16:09:29 GMT Server: Apache/2.4.29 (Ubuntu) X-Frame-Options: sameorigin X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff Strict-Transport-Security: max-age=31536000 Content-Security-Policy: default-src 'none';script-src 'self' 'unsafe-eval';connect-src 'self';img-src 'self' data:;style-src 'self' 'unsafe-inline';font-src 'self'; Access-Control-Allow-Origin: * Content-Length: 0 Connection: close Content-Type: application/json
Can someone help me ? Thanks
@tom-elliott yes, Zm9nOnBhc3N3b3Jk (default fog:password), as you can see on screenshot. I’m also create new user, enable API for him and get same result.
And same result with curl:
[root@ ~]# curl -H 'fog-api-token: <token>' -u fog:password -X GET http://<fog-ip>/fog/system/status [root@ ~]# curl -H 'fog-api-token: <token>' -H 'Authorization: Basic Zm9nOnBhc3N3b3Jk' -X GET http://<fog-ip>/fog/system/status [root@ ~]# curl -H 'fog-api-token: <token>' -H 'fog-user-token: <token>' -X GET http://<fog-ip>/fog/system/status **success**
Only auth with two tokens work fine.
Tom Elliott last edited by
@90amper and the user:password is first your GUI username and password, the. Base64 encoded?
Hello! Both of basic auth methods still not work (login:pass auth and base64 header). Tokens works properly. I’m try connecting to FOG 1.5.9 on CentOS 7 server from Postman app and recieve 403 error.
What OS are you using to connect to the api?
Shameless plug here for the api powershell module. I have a function called
Set-FogServerSettingsthat helps with just inputting the api keys and it will handle the authentication from there with any function call. See the links in my signature. I originally made it cross-platform but it’s currently more windows oriented. Due to COVID-19 I am not working, which means I might have some free time (I say might because I also have a new baby). If you’re not running on windows I can dedicate some time to adding more linux support to the module since powershell core 6 and 7 are both cross platform on linux, mac, and windows.
The module takes that simplified documentation and creates tab completable functions from the structure outlined in the documentation.
@eseo-fcolas Found some time to take a look at this again. You are right about the documentation saying
curl -H 'fog-api-token: AbCdE...' -H 'Authorization: Basic Zm9nOnBhc3N3b3Jk' -X GET http://fogserver/fog/system/status success
Works as well as the following call on my FOG test server (currently a Fedora 30 VM):
curl -H 'fog-api-token: AbCdE...' -u fog:password -X GET http://192.168.2.30/fog/system/status success
Are you sure you are using the fog web UI user’s password when testing?
I would say this is working as intended and described in the API documentation. But if you still see the same issue happen I may ask you to provide information in the FOG version you use and Linux OS (we see Ubuntu in the headers but which version)?
I remember we had a more general API issue on Ubuntu servers some time ago. But back then it wouldn’t succeed with the api-user-token either and I don’t expect you to have that same issue.
Ok, effectively it works with the api-user-token. The doc says it’s also working with the user:pass method. Thanks
@eseo-fcolas You need to add the fog user API token to the URL as well. There are a couple of examples in the forums. Forum search should help you finding those.