OAuth 2.0 authenticated GraphQL I/O Doc usage reference
The OAuth 2.0 authentication is determined by the Request Authentication Type and Grant Type settings configured on the Key & Method Detection page and the API Definition Security Settings page, and the API Management Token API setting configured on the API Definition Security Settings page.
Depending on the OAuth 2.0 authentication configuration on these two pages, the GraphQL editor automatically loads the correct credential form. The developer must provide a valid Bearer token in the GraphQL editor's authentication field.
After providing the Bearer token, adding the query fields, and clicking Execute query, the editor sends your token with the request to the server as an Authorization: Bearer header, and the response results appear on the right side of the interface.
Use case: OAuth 2.0
The following is an example of how to test an OAuth 2.0 authenticated GraphQL I/O Doc on the Developer Portal > Interactive Documentation page.
Adding a query
On the left-hand side, the editor automatically fetches all the query fields from the schema configured for an endpoint on the Key & Method Detection page.
The Request Authentication Type is set to OAuth 2.0, and Grant Type is set to Client Credentials on the Key & Method Detection page and API Definition Security Settings page, and API Management Token API is enabled on the API Definition Security Settings page. Next, ensure you have configured the public and backend domains and paths for both the GraphQL endpoint and the Token endpoint on the Domains & Traffic Routing page. Review Prerequisites for using OAuth 2.0 authenticated GraphQL I/O Doc for more information.
Then, obtain a bearer token from the token endpoint and provide it in the GraphQL editor’s authentication field. To obtain a Bearer token, exchange your application's API key (client ID) and shared secret with the token endpoint using the Client Credentials flow:
# Step 1: Get token
curl -s -X POST 'https://<your-portal>/<token-endpoint-path>' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=client_credentials&client_id=<your-api-key>&client_secret=<your-secret>'
# Step 2: Call API
curl -X POST 'https://<your-portal>/<graphql-endpoint-path>' \
-H 'Authorization: Bearer <access_token_from_step1>' \
-H 'Content-Type: application/json' \
-d '{"query":"{ items { id name } }"}'
To test your GraphQL API, copy the access_token value from the Step 1 response and paste it into the GraphQL editor's authentication field. Attach the Bearer before the token, for example, Bearer <access_token_value>. Add query fields or write a query directly in the editor, then click Execute query. The editor sends your token in the request header for authorization with every request. On the right-hand side, the query returns results as a JSON object in the editor.
