Token Endpoint for OAuth2
Hello, I am working with @Alberto Fuentes https://openexchange.intersystems.com/package/workshop-iris-oauth2.
I wonder how do I get a token to send to the resserver?
I tried calling "token_endpoint" : "https://webserver/authserver/oauth2/token"
The response was "error":"invalid_request","error_description":"Unknown grant_type"
I wonder what needs to be in the request body? Is it a GET or POST?
Comments
To obtain a token from the token endpoint using OAuth 2.0, the correct method involves making a POST request. The body of the request should use the required grant_type along with other relevant parameters. Here are the details:
- To use the password grant type (
grant_type=password), the request body should typically include:client_id: This is the client application identifier.client_secret: The secret associated with the client application.grant_type: This should be set topassword.username: The resource owner’s username.password: The corresponding password.scope: Optionally specify desired scope(s) delimited by spaces.
For example, the request body might look like this:
{
"client_id": "clientid",
"client_secret": "clientsecret",
"grant_type": "password",
"provision_key": "provisionkey",
"authenticated_userid": "1"
}
This JSON would be part of a POST request to the /oauth2/token endpoint 1.
- If you’re using the authorization code grant type (
grant_type=authorization_code), then the body should contain:grant_type: Set toauthorization_code.code: The authorization code obtained from the initial authorization step.redirect_uri: The same redirect URI used when requesting the authorization code.client_idandclient_secret: Identifiers for your application.
Ensure the Content-Type header of the request is set to application/x-www-form-urlencoded as the body is usually URL-encoded 23.
Additionally, ensure that the authorization server configuration supports the requested grant type. Details such as provisioning keys or additional fields may depend on the specific implementation and need to be verified in your setup 1. If errors persist because of unknown grant types, confirm that the relevant settings in the authorization server are correct 2.
Sources: