user1184777
user1184777

Reputation: 1027

Insomnia configure OAuth 2.0 grant_type password access token for other API calls

I am trying to embed OAuth 2.0 grant_type password access token to my insomnia client API calls but getting "Failed to fetch token url= state us=0" enter image description here

When we try below curl command its returning the access token. each time we have to copy access token and add it as header in insomnia rest call (Their is no client secret as it not confidential).

curl --request POST \
--url https://mydomain/auth/realms/my-app/protocol/openid-connect/token \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data client_id=myclientid \
--data username=app.admin \
--data 'password=password!' \
--data grant_type=password 

Above curl if you create in insomnia client as POST request that is also working only thing is we need to copy and paste as header in other API calls enter image description here

NOTE: the same is working in postman rest client through pre-request script but I want it to be achieved in insomnia client

Upvotes: 0

Views: 10122

Answers (1)

user1184777
user1184777

Reputation: 1027

After doing lot of research found out the solution by myself follow this blog https://www.ankursheel.com/blog/automatically-set-access-token-authenticated-requests-insomnia

You need to create separate Generate token request, and set the bearer token in the API request where you want to embed Auth token automatically, click on the Bearer tab and enter Response ⇒ Body Attribute for the token and follow those instruction it worked for me :)

Upvotes: 3

Related Questions