cancel
Showing results for 
Search instead for 
Did you mean: 

How to use access token in authorization from another API

SOLVED
Behdad
Occasional Contributor

How to use access token in authorization from another API

Hi

I am using JWT token in my Rest APIs and as it has expiration time , i need to refresh/get new token during my test case 

So here is an example :

1. first test step --> I create new Token using auth/api-key endpoint

2. second test step --> use this token in another Api endpoint to create new client (/client/create) as access token in authorization 

In this case i try to use data transfer between this 2 step , and receive new token but can manage to use it as access token in target !

 

in between , i am not good in scripting so i prefer to do it via available tools & pages in ReadyAPI 3.5.0

 

Thanks in advance

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
richie
Community Hero

Re: How to use access token in authorization from another API

Hey @Behdad,

So youre saying youre using the OAuth functionality for your token generation, right....so the token isnt returned in a response payload nor a response header...is that correct?

If that is the case, someone else recently had the same issue and i think i remember @HimanshuTayal trying to determine which internal object/property the token value was associated with.
I can't remember if Himanshu sorted it out, but have a search in the soapui AND readyapi! forums for the answer.


Have a look at the following link, and report back your progress

https://community.smartbear.com/t5/SoapUI-Open-Source/Using-context-parameter-in-Request-Authorizati...

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

View solution in original post

6 REPLIES 6
richie
Community Hero

Re: How to use access token in authorization from another API

Hey @Behdad,


Can you clarify? I didnt understand where you state "In this case i try to use data transfer between this 2 step , and receive new token but can manage to use it as access token in target !"

The way i have setup token property transfer before is i have a disabled setup suite that contains the api that generates the auth token. I have a property transfer step in this setup suite that moves the auth token value to a Project level property.

I have my functional test case (containing the REST step that USES the token) within a enabled test suite. The first test step in my functional testsuite is a RunTestCase step that executes the generate auth token testcase/step that is in the disabled setup suite (which when executed updates the Project level property with the new auth token value).
My next step is my functional REST step that sources the auth token value from the Project level property.

The above approach means if you run the project, the disabled test suite doesnt execute unless its called by a functional test suite. Another advantage to this approach is that you dont have to worry about the token expiring, cos the first step in each functional test suite is the RunTestcase test step which re-executes the teststep that generates the auth token.

Does that help? As i said above, i didnt really understand what you meant, so ive kindof guessed as to what you asked.

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
sonya_m
Community Manager

Re: How to use access token in authorization from another API

Thank you Richie!

 

@Behdad does this help? Please let us know🙂


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Behdad
Occasional Contributor

Re: How to use access token in authorization from another API

Hi  

Many thanks for your suggestion, that is somehow  what I do for now , but it is not automated way to handle that case and some how we need to run test case two time and transfer the token manually.

let me gave more clear detail and hope you find a way to handle it 🙂

1-I have Rest api as first test step that create JWT token (with Josn request) and receive token in response as string

2- So i can add this response as new JWT token and be able to use it for property transfer (for example)

3- In my next rest service/test step, i need to use this token in Authentication tab as Access token and then run it as second test step but cant! (or i dont know how ?)

That is my issue , i am looking for a way to do it via same test case and run both of these steps in same test case.

 

 

richie
Community Hero

Re: How to use access token in authorization from another API

Hey @Behdad 

 

Ok - so what you're saying is - you have a single testcase with 2 REST requests in there.

 

The 1st REST request generates a response that includes the auth token

The 2nd REST request needs the auth token, but you're not sure how to do the property transfer between the two steps (or transfer to a Properties step or transfer to the TestCase level property), or whatever- is that correct?

 

Apologies - but there's no point me trying to answer a question  you don't want answered - hence I just like to be absolutely clear what you mean!

 

ta

 

rich

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Behdad
Occasional Contributor

Re: How to use access token in authorization from another API

Hi 

To make it more clear let keep your lates post and here is my situation

I have a single test case with 2 REST requests in there:

1- The 1st REST request generates a response that includes the auth token.

2- The 2nd REST request needs the auth token generated by the first /previous rest service, so i don't know how to use the token in first api response in  second one as access token in authorization tab

in this case i try the property transfer between the two steps but can not manage to receive the token in second step (as access token for authorization)

Tags (1)
richie
Community Hero

Re: How to use access token in authorization from another API

Hey @Behdad,

So youre saying youre using the OAuth functionality for your token generation, right....so the token isnt returned in a response payload nor a response header...is that correct?

If that is the case, someone else recently had the same issue and i think i remember @HimanshuTayal trying to determine which internal object/property the token value was associated with.
I can't remember if Himanshu sorted it out, but have a search in the soapui AND readyapi! forums for the answer.


Have a look at the following link, and report back your progress

https://community.smartbear.com/t5/SoapUI-Open-Source/Using-context-parameter-in-Request-Authorizati...

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors