I am creating a secured back-end for a new app with Keycloak and NestJS. I imported my realm with clients and user in it and I am trying to get the token and access protected data through Insomnia.
Trying to reach endpoint {{ _.baseUrl }}/protocol/openid-connect/auth
with a POST
request passing data through JSON is returning
keycloak-1 | 2024-03-11 16:01:56,436 WARN [org.keycloak.protocol.oidc.endpoints.request.AuthorizationEndpointRequestParserProcessor] (executor-thread-131) Parameter 'client_id' not present or present multiple times in the HTTP request parameters
keycloak-1 | 2024-03-11 16:01:56,437 WARN [org.keycloak.events] (executor-thread-131) type="LOGIN_ERROR", realmId="55542514-fc71-4e4e-be3e-42af869de2a7", clientId="null", userId="null", ipAddress="172.18.0.1", error="invalid_request"
in my Docker Keycloak logs and a 400 Bad request error
in Insomnia response preview window.
At first I was only passing my credentials and the error made me rethink the whole thing and pass client_id and client_secret as well i the JSON data yet error i still the same.
I was following this tutorial but it does not seem suitable for a Keycloak environment
How to reach to my Keycloak endpoints via Insomnia and furthermore how to get more verbose logs in the future ?
Insomina is a little hard.
#0 Keycloak launching Detail in here
Access Token URL
POST "http://localhost:8180/realms/master/protocol/openid-connect/token"
The token_endpoint
should be match Insomnia URL PREVIEW
If not, 404 not Found Error
#1 Crete New Collection
#2 Name as Keycloak
#3 Click Gear Icon for setting
#4 Base Environment
{
"baseUrl": "http://localhost:8180",
"username": "admin",
"password": "admin",
"access-token": ""
}
#5 Add HTTP Request
#6-7 Create Get-Token
by POST API
#8 CTRL + Space Can add get environment variable
detail in here
#9 Make URL with an environment variable
{{ _.baseUrl }}/realms/master/protocol/openid-connect/token
#10 Add Body key/value by Form URL Encoded
It is same as /x-www-form-urlencoded
in Postman
#11~13 Add 4 keys/value
User name and password get from environmental variable
By CTRL + Space
#14 Get token Click Send
#1 Open Base Environment
In the access-token
place cursor inside ""
CTRL+Space
Select f Response => Body Attribute
Result
#2 Click reponse 'body', '', '', 'never',60
Select: Request POST Get Token
Filter (JSONPath or XPath)
$.access_token
Finally, get user list with access-token