• Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Authenticate on FOG API

    Scheduled Pinned Locked Moved Solved
    FOG Problems
    api help
    5
    8
    1.3k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      eseo-fcolas
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • S
        Sebastian Roth Moderator
        last edited by

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

        Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

        Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

        1 Reply Last reply Reply Quote 0
        • E
          eseo-fcolas
          last edited by eseo-fcolas

          Ok, effectively it works with the api-user-token. The doc says it’s also working with the user:pass method. Thanks

          1 Reply Last reply Reply Quote 0
          • S
            Sebastian Roth Moderator
            last edited by

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

            Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

            Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

            1 Reply Last reply Reply Quote 0
            • JJ FullmerJ
              JJ Fullmer Testers
              last edited by JJ Fullmer

              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.

              Have you tried the FogApi powershell module? It's pretty cool IMHO
              https://github.com/darksidemilk/FogApi
              https://fogapi.readthedocs.io/en/latest/
              https://www.powershellgallery.com/packages/FogApi
              https://forums.fogproject.org/topic/12026/powershell-api-module

              1 Reply Last reply Reply Quote 2
              • 9
                90amper
                last edited by

                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.
                a7f4df76-f865-4626-8c2c-7cecb7492bc4-image.png
                57ae69eb-e7e3-4abf-a4ef-5c762c88d074-image.png

                Tom ElliottT 1 Reply Last reply Reply Quote 0
                • Tom ElliottT
                  Tom Elliott @90amper
                  last edited by

                  @90amper and the user:password is first your GUI username and password, the. Base64 encoded?

                  Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

                  Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                  Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                  9 1 Reply Last reply Reply Quote 0
                  • 9
                    90amper @Tom Elliott
                    last edited by 90amper

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

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      Last post

                    153

                    Online

                    12.0k

                    Users

                    17.3k

                    Topics

                    155.2k

                    Posts
                    Copyright © 2012-2024 FOG Project