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

The request body must contain the following parameter: 'grant_type' #232

Open
Ramguru94 opened this issue Aug 17, 2023 · 2 comments
Open

Comments

@Ramguru94
Copy link

unexpected response code '400': {"error":"invalid_request","error_description":"AADSTS900144: The request body must contain the following parameter: 'grant_type'.

I am trying to create Bearer token for a Azure service principal.

Provider.tf contains

provider "restapi" {
  alias = "restapi_bearer"
  uri   = "https://login.microsoftonline.com/"
  headers = {
    Content-Type = "application/json"
  }
  create_method        = "POST"
  write_returns_object = true

}

resource.tf contains

resource "restapi_object" "sp" {
  path = "/${azuread_service_principal.tenant_sp.application_tenant_id}/oauth2/v2.0/token"
  data = jsonencode({
    grant_type    = "client_credentials"
    client_id     = "${azuread_service_principal.tenant_sp.application_id}"
    scope         = "2ff814a6-3304-4ab8-85cb-cd0e6f879c1d%2F.default"
    client_secret = "${azuread_application_password.tenant_sp.value}"
  })
}

My data has grant_type set and still i am getting 400

Am i missing something or doing this wrong!

@Ramguru94
Copy link
Author

2023-08-17T16:10:41.860+0200 [INFO]  provider.terraform-provider-restapi_v1.18.1: 2023/08/17 16:10:41 api_client.go: Request headers:: timestamp=2023-08-17T16:10:41.860+0200
2023-08-17T16:10:41.860+0200 [INFO]  provider.terraform-provider-restapi_v1.18.1: 2023/08/17 16:10:41 api_client.go:   Content-Type: application/json: timestamp=2023-08-17T16:10:41.860+0200
2023-08-17T16:10:41.860+0200 [INFO]  provider.terraform-provider-restapi_v1.18.1: 2023/08/17 16:10:41 api_client.go: BODY:: timestamp=2023-08-17T16:10:41.860+0200

the BODY part looks empty ?

@majosula
Copy link

majosula commented Mar 7, 2024

I am fighting with the very same problem. Did you find a solution for this?

resource "restapi_object" "get_token" {
path = "/api/oauth2/token"
debug = true
data = jsonencode({
grant_type = "password"
username = var.user
password = var.pwd
refresh_token = ""
code = ""
use_short_term_refresh = ""
vbr_token = ""
})
}

Error: unexpected response code '400': {
│ "errorCode": 0,
│ "message": "TokenLoginSpec.GrantType : 'Grant Type' must not be empty. ",
│ "resourceId": null
│ }

│ with restapi_object.get_token,
│ on mastercard.tf line 22, in resource "restapi_object" "get_token":
│ 22: resource "restapi_object" "get_token" {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants