HOW TO BUFFER API OAUTH 2.0 TOKEN
Situation
A customer wants to buffer the OAuth 2.0 Token.
Solution
- Open API scan and add the Token endpoint in the endpoint field and other details to generate the token in payload as shown below
Syntax :- Field1=Value1& Field2=Value2 Eg:- grant_type=password&client_id=2ad88395-b77d-4561-9441-d0e40824f9b
- Add the header Content-type: application/x-www-form-urlencoded
- Run the request to generate the Token
- Once the Token is generated create an API test case of the same and go to response module create the Token ModuleAttribute
- Once the module attribute is created navigate to the test case and add buffer name to save token
- Below are the results of the execution
Harish Krishnadas
If the Values of "Client_ID", "Client_Secret" has special characters then you have convert them to URLEncoded format first and then send the Request, else you will be getting "400 Bad Request" with Message "InValid error"
How to Convert to URLEncoded?
You can use below free site for converting to URLEncoded format
https://www.urlencoder.org/
Thanks,
Harish
BILEL TAIEB
Hello Pavan,
Thank you for this interesting article.
I would like to know please, after having buffered the token, how can we insert it (automatically) in the main webservice (the webservice that uses this token to authenticate).
Thank you in advance for your answer
Pavan Meharwade
Hi Bilel,
You can create the module attribute of the Authorization header in the main web service request and in the test case of the main web service request you can pass the buffer value so that it takes the buffer token in it.
Regards
Pavan
Sebastian Holz
Thank you very much. Saved my day!
Diyor Fayziev
Hi Pavan and All,
I was able to Buffer the response value (Token) and created Module Attribute to store the token, however I'm not able to pass the buffer value as a header to another request. Can you please share best practice to pass buffer value as a header attribute?
Thanks,
Diyor