Forum Discussion
Hi Sriraj, I was also ran into similar issue and one of the community member helped with groovy method. In my example I have only one Auth profile but I could have multiple in future.
Implementation:
I used this in event handler - TestRunListener.beforeRun - by doing this, script is checking at the beginning of a testcase if token is expired or not. if expired then retrieves from the server.
Script:
import com.eviware.soapui.impl.rest.actions.oauth.OltuOAuth2ClientFacade
import com.eviware.soapui.support.editor.inspectors.auth.TokenType
import com.eviware.soapui.impl.rest.OAuth2Profile.*
//Get Project
def project = testRunner.testCase.testSuite.getProject()
//Get oAuth Profile Name
def oAuthProfilelist = project.getOAuth2ProfileContainer().getOAuth2ProfileNameList()
def oAuthProfileName
if(oAuthProfilelist.size() == 1){
oAuthProfileName = oAuthProfilelist[0]
log.info "oAuth Profile name is: $oAuthProfileName"
}
//Get Token Status
def oAuthProfile = project.getAuthRepository().getEntry("$oAuthProfileName")
def TokenStatus = oAuthProfile.accessTokenStatus.toString()
log.info "Access Token Status is: $TokenStatus"
//Get Access Token from the server if expired
if (TokenStatus != 'RETRIEVED_FROM_SERVER'){
def oAuthClientFacade = new OltuOAuth2ClientFacade(TokenType.ACCESS)
oAuthClientFacade.requestAccessToken(oAuthProfile, true)
log.info "Access Token Status is "+ oAuthProfile.accessTokenStatus
}
since you have multiple profiles, you could iterate through them and update token.
Hope this helps!
Hey,
I have question on AUTO generating toke on expiration.
Created discussion https://community.smartbear.com/t5/SoapUI-Pro/how-to-automate-our-manual-Oauth2-0-process/m-p/183496#M41955
As suggestion I tried implementing 'TestRunListener.beforeRun' with given script and no luck.
My token have pretty much good expiration, to test auto generation I screw up exisitng token and test them automation.
It works when I manually update token (Generate Token)
READY API 2.6.0
NOTE: AUTO REFRESH of my token is not set, so I need to create new toke when its expired.
Any help is highly appreciated.
- TanyaYatskovska6 years agoSmartBear Alumni (Retired)
Hi Preerab,
Let's keep the conversation in the topic you've started for the issue:
https://community.smartbear.com/t5/SoapUI-Pro/how-to-automate-our-manual-Oauth2-0-process/m-p/183485
This will help everyone be one the same page as the discussion goes in one thread.
Related Content
- 2 months ago
Recent Discussions
- 19 days ago