Packer API Authentication

Hello HashiCorp Community,
I was recently trying to automate my build and deploy process.
I was following this API Doc
I have created the required service principal, but I couldn’t find any documentation about how to authenticate Packer API’s via service principal through REST.


Hi @kuldeeprishi, Thanks for your feedback! I already passed this feedback internally and we will see options to add those information.

In the meantime, you can manually obtain your OAuth 2.0 access token using your HCP credentials (client ID/secret) using curl or any tools that work for you (e.g., Postman).

For instance, try this curl command by replacing $HCP_CLIENT_ID and $HCP_CLIENT_SECRET with yours (i.e., service principal key), then you will get one as below:

  --data 'grant_type=client_credentials&audience=' \
  '' | jq
  "access_token": "your_access_token_here",
  "expires_in": 3600,
  "token_type": "Bearer"

Once you got your access_token, now you can call APIs using that access token by sending an authorization request header -H 'Authorization: Bearer <your_access_token>'

You can also use our official Go SDK for HCP API: GitHub - hashicorp/hcp-sdk-go: Go SDK for HCP API. and from there, you could see the auth implementation in action:


Thanks a lot @shohei
This was indeed very helpful :+1: