cancel
Showing results for 
Search instead for 
Did you mean: 

Not automatically refreshing authorization access token

SOLVED
Highlighted
Occasional Contributor

Not automatically refreshing authorization access token

I have a test that retrieves authorization access token and I set it to automatically refresh after 1 second. Meaning I want it to to get access token for every time it is run. It is not refreshing the token. I just see an error sign saying token has expired. It is not auto refreshing. What is going on?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Occasional Contributor

Re: Not automatically refreshing authorization access token

To clarify, would be great if this auto token refresh feature worked when using the 'Client Credentials Grant' method of getting the token.

 

I can make an step that gets access token from our authorization server and put into a testsuite custom property. All the request steps will then use this token for their Authorization headers. This is alot simpler.

View solution in original post

10 REPLIES 10
Highlighted
Community Hero

Re: Not automatically refreshing authorization access token

Hey anagai,

Im guessing before anyone can provide any help forum members will need to know a little more.

Whats the authentication/authorization scheme youre using?
Is it OAuth youre using? If yes, whats the grant type?
Are you using the embedded OAuth functionality along with javascript to do what you need?
If you have scripts can you post them so people can review?

Ive seen over the last year a number of posts (via soapui/readyapi! forum and stackoverflow) cos people are having trouble automatically refreshing the token for OAuth v2.0....perhaps these previous posts might help you?

Cheers

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
Highlighted
Occasional Contributor

Re: Not automatically refreshing authorization access token

I am using OAuth 2 - Client Credentials Grant. I have the settings correct and is retrieving the token. There is no javascript. Not authenticating on any page. I simply want the getting of a new token on every test for now, because I just want to see if that auto refresh feature even works. I have seen some of the post regarding this. For now I just want an explanation exactly how this feature works. The option says Refresh Access Token: Automatic and I set the expire to 1 second. I am to conclude that when token expires it will automatically get a new token without me having me to click on get token. This does not seem to be happening. Is this how it is supposed to work? I could not find a really clear explanation on the documentation. Maybe you can point me to a place where I can understand this feature.

Highlighted
Community Hero

Re: Not automatically refreshing authorization access token

Hey @anagai,

The reason i mentioned javascript is cos the readyapi! Help for OAuth v2.0's automation of token retrieval uses javascript to simulate interactions with a webpage to refresh the token. Im assuming its the same for SoapUI considering Smartbear havent developed a GUI method to do this....?

Have a look at the following link. This might help

https://support.smartbear.com/readyapi/docs/requests/auth/types/oauth2/automate/sample.html

Cheers,

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
Highlighted
Occasional Contributor

Re: Not automatically refreshing authorization access token

Ok, then this auto refresh feature is not going to work in this use case. I do not need to go to a page and refresh a token with javascript.

 

Lets say I have 50 rest api requests in a test suite and each requires an access token. Before I run the suite I have to go into each step and click on that get token button to get a new token. This is highly inefficient If I have 50 steps in a suite. Would be awesome if there was an auto refresh feature that upon soup ui start will know tokens are expired and automatically retrieve tokens per api request step. After that point keep track if tokens need to be refreshed after set period of time.

Highlighted
Occasional Contributor

Re: Not automatically refreshing authorization access token

To clarify, would be great if this auto token refresh feature worked when using the 'Client Credentials Grant' method of getting the token.

 

I can make an step that gets access token from our authorization server and put into a testsuite custom property. All the request steps will then use this token for their Authorization headers. This is alot simpler.

View solution in original post

Highlighted
Community Hero

Re: Not automatically refreshing authorization access token

Hey @anagai

I have various different OAuth v2.0 projects in my workspace and some use the embedded OAuth functionality, others ive had to.setup the various back and forth REST requests and others are single REST call to generate the access token which i save to a Project property which is then called for each request as you describe. It just depends on the technical architecture. Obviously the single REST call to generate the access token is the most straighforward.

You could submit a new feature request to Smartbear to add the auto refresh functionality to the embedded functionality. Im sure there would be no shortage of upvotes!

Cheers

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
Highlighted
Frequent Contributor

Re: Not automatically refreshing authorization access token

I just wanted to share an approach I use for Token ID.

 

I have a script that all it does it retrieve a token ID.  

I have this setup (for me in team City) to run every 2 hours and in a automation DB

these Token IDs for various users are stored.  So I always have valid non expired token ID available

for scripts to use.

 

When running my Projects in SoapUI, the first test script, per my test env and user

retrieves the token ID from the DB, stores it in a Project Custom variable.  

 

As each of the my scripts execute in my TestSuite, they retrieve this TokenID from the project level

and I build it into my header as a Bearer value.

 

JamesK
Highlighted
Community Hero

Re: Not automatically refreshing authorization access token

Hey @jkrolczy,

In regards to the automatic refresh every 2 hours....how do you achieve this? Have you got this functionality coded in a groovy step perhaps?

If this is the case, would you post the code?
Im intrigued. I dont know how youd code this to automatically refresh without executing a step or am i misunderstanding?

I dont know how to get an auto refresh at a specific interval so would welcome the education!

Cheers

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
Highlighted
Community Manager

Re: Not automatically refreshing authorization access token

@jkrolczy I see you replied to Richie straight to the email notification. Please copy your reply here, thank you.


Sonya Mihaljova
Community and Education Specialist
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors