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 1.9k 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

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  • First post
                    Last post