0

I need to send a request like the one below.

curl --request POST --url https://dev-jlsubxnitkpok2tw.au.auth0.com/oauth/token 
--header 'content-type: application/json' \
--data '{"client_id":"","client_secret":"","audience":"","grant_type":"client_credentials"}'

I am using Ballerina like below

http:Client securedEP = check new ("http://postman-echo.com", {
            auth: {
                tokenUrl: "xxx/oauth/token",
                clientId: "xxx",
                clientSecret: "xxx",
                scopes: ["read", "submit"]
            }
        }

I get an error like the one below from the service.

cause: Failed to get a success response from the endpoint. Response code: '403'. 
Response body: '{"error":"access_denied","error_description":"No audience 
parameter was provided, and no default audience has been configured"}'

How can I achieve this in Ballerina?

Niveathika
  • 1,319
  • 2
  • 8
  • 17
Krv Perera
  • 119
  • 2
  • 15

1 Answers1

1

You can use the optionalParams parameter in ClientCredentialsGrantConfig to specify that.

http:Client securedEP = check new ("http://postman-echo.com", {
        auth: {
            tokenUrl: "xxx/oauth/token",
            clientId: "xxx",
            clientSecret: "xxx",
            scopes: ["read", "submit"],
            optionalParams: {
                "audience": "aud"
            }
        }
    });

Note that the auth record field here is coming from CommonClientConfiguration type.

Imesha Sudasingha
  • 3,462
  • 1
  • 23
  • 34