Authenticate on FOG API



  • Hello,

    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


  • Testers

    What OS are you using to connect to the api?
    Shameless plug here for the api powershell module. I have a function called Set-FogServerSettings that 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.


  • Senior Developer

    @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


  • Senior Developer

    @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.


Log in to reply
 

449
Online

7.4k
Users

14.5k
Topics

136.5k
Posts