Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get proper response from Auth0 get token call #304

Closed
1 task done
tommy38hk opened this issue Jul 31, 2023 · 5 comments
Closed
1 task done

Unable to get proper response from Auth0 get token call #304

tommy38hk opened this issue Jul 31, 2023 · 5 comments
Labels

Comments

@tommy38hk
Copy link

Terraform CLI and Provider Versions

Terraform v1.4.6

Terraform Configuration

data "http" "auth0_token" {
  url = var.auth0_token_endpoint
  request_body = local.auth0_json
  method = "POST"
  request_headers = {
    Accept = "application/json"
  }
}
locals {
  auth0_json=jsonencode({
    client_id     = var.auth0_client_client_id
    client_secret = var.auth0_client_client_secret
    audience      = var.edms_registration_service_api_identifier
    grant_type    = "client_credentials"
  })
}
output "auth0_json_response" {
  value = data.http.auth0_token.response_body
}
output "auth0_json_request" {
  value = local.auth0_json
}

Expected Behavior

Be able to return the auth0 token

Actual Behavior

auth0_json_response = "{"error":"access_denied","error_description":"Unauthorized"}"

Steps to Reproduce

  1. terraform apply

How much impact is this issue causing?

Medium

Logs

No response

Additional Information

Proper token can be obtained using CURL command for the same credentials

Code of Conduct

  • I agree to follow this project's Code of Conduct
@tommy38hk tommy38hk added the bug label Jul 31, 2023
@austinvalle
Copy link
Member

austinvalle commented Jul 31, 2023

Hi there @tommy38hk 👋🏻 , thanks for filing the issue and sorry you're running into trouble here.

Are you able to share the CURL command structure you're using that is successfully making the API call?

The example configuration you provided looks like it's encoding the HTTP request body as application/json, whereas the Auth0 documentation for POST /oauth/token is expecting application/x-www-form-urlencoded in the request body.

@tommy38hk
Copy link
Author

tommy38hk commented Jul 31, 2023

Hi @austinvalle
Here's the CURL command from Auth0, I have replaced the actual values of the sensitive fields.

curl --request POST
--url https://my.auth0.com/oauth/token
--header 'content-type: application/json'
--data '{"client_id":"my-auth0-client-id","client_secret":"my-ayth0-client-secret","audience":"my-auth0-api-audience","grant_type":"client_credentials"}'

image

@austinvalle
Copy link
Member

Quick test before I try and reproduce that issue, can you try updating your data block to use the Content-Type header, currently it only has Accept set:

data "http" "auth0_token" {
  url = var.auth0_token_endpoint
  request_body = local.auth0_json
  method = "POST"
  request_headers = {
    content-type = "application/json"
    accept = "application/json"
  }
}

@tommy38hk
Copy link
Author

Yes, that fixed the issue. Thank you so much

Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants