XCP-ng
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    REST API token generation via curl

    Scheduled Pinned Locked Moved REST API
    7 Posts 3 Posters 860 Views 5 Watching
    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.
    • D Offline
      dan89
      last edited by

      Is there a method available, or planned, to generate a REST API token via curl? My environment currently has tokens set to expire after 72 hours and regenerating it via xo-cli or pulling it through the web UI is an extra manual step.

      Being able to run something similar to the below to generate and store a token would help with automating some tasks I am looking to do on a scheduled basis

       curl --location 'https://XOA.company.lan/rest/v0/authorization/token' --data-urlencode 'grant_type=password' --data-urlencode 'username=admin' --data-urlencode 'password=P@$$w0rd'
      
      julien-fJ 1 Reply Last reply Reply Quote 0
      • olivierlambertO Offline
        olivierlambert Vates 🪐 Co-Founder CEO
        last edited by

        Ping @julien-f

        1 Reply Last reply Reply Quote 0
        • julien-fJ Offline
          julien-f Vates 🪐 Co-Founder XO Team @dan89
          last edited by

          @dan89 Nope, there is no way to achieve that this time.

          Why is it easier than xo-cli --createToken https://XOA.company.lan admin password?

          D 1 Reply Last reply Reply Quote 0
          • D Offline
            dan89 @julien-f
            last edited by

            @julien-f some of the scripts I need to be run can't always run on the XOA appliance and need to be run on other Linux/Windows hosts so the output can be manipulated for use via other programs/methods.

            Having a way to pass authentication through curl would give the ability to generate a token when not running scripts on the main XOA appliance.

            julien-fJ 1 Reply Last reply Reply Quote 0
            • julien-fJ Offline
              julien-f Vates 🪐 Co-Founder XO Team @dan89
              last edited by

              @dan89 I understand 🙂

              But FYI, xo-cli can be installed on other machines than the XOA.

              Also, IMHO, it's better to use longer tokens instead of exposing credentials on your machines.

              D 1 Reply Last reply Reply Quote 0
              • D Offline
                dan89 @julien-f
                last edited by

                @julien-f slightly off topic then, but is there a way to extend token expiration for a single user and not globally? Or to have a single user excluded from the global default?

                julien-fJ 1 Reply Last reply Reply Quote 0
                • julien-fJ Offline
                  julien-f Vates 🪐 Co-Founder XO Team @dan89
                  last edited by

                  @dan89 Yes, you can pass the --expires flag to change the validity of a token. But you cannot go above maxTokenValidity though you can increase it in your xo-server's config.

                  Example:

                  xo-cli --createToken --expiresIn 90d https://XOA.company.lan admin password
                  
                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post