Forum Discussion
Hey Jainsoumya
When you get a response from SmartBear regarding the support ticket - would you mind publishing the results please?
Refreshing the OAuth token has always been problematic, so I'd be interested to see a solution.
I do know someone put a script together that actually worked and posted the solution - I'll have a search and see if I can find it.
that's all I got for now I'm afraid!
Cheers,
Rich
Hey richie
Sure !! I'll do that
- Jainsoumya3 years agoContributor
Hi sonya_m
I have automated the script till I get the token in server , I have attached the screenshot for the same ,
I am not that good in scripting so can you help how to get this token in use in the script
- ciuz99best3 years agoRegular Visitor
Jainsoumya Hi, I'm not really sure if this is what you're looking for, but maybe it'll come in handy, you can just create a new groovy script step before everything in order to refresh the token. Go here to the 'Forced token update' section and copy the script from there. Hope it helps you.
- mkrausem3 years agoOccasional Contributor
Hi,
we update our tokens via the SubmitListener - beforeSubmit-Event
Our groovy checks the status of the required token and updates if it is older than x minutes (because the automatic function not works)
Kind Regards, Michael
- New2API3 years agoFrequent Contributor
Jainsoumya, looks like you are using OAuth (1 or 2) for your access token.
Once you configure your authProfile to retrieve token, you can use event handlers to run your scripts to automatically update token.
We have implemented very similar approach. we are using TestRunListener.beforeStep and this script will be called only for a REST step (this is done using script logic). you also could do this for SubmitListener.beforeStep event too.
//## Get Project ##//
def project = testRunner.testCase.testSuite.getProject()//## Get TestStep ##//
def TestStep = context.getCurrentStep()//## Get oAuth Profile Name ##//
def oAuthProfileName
def oAuthProfile
def TokenStatus
def oAuthClientFacade
def currentToken
def ENV
def i = 0
if (TestStep.config.type == 'restrequest'){//## get current environment ##//
log.info "Running GetAccessToken event script..."
ENV = testRunner.testCase.testSuite.project.activeEnvironment.name
log.info "test environment is $ENV..."
//## Get oAuth profile name list ##//
def oAuthProfilelist = project.getOAuth2ProfileContainer().getOAuth2ProfileNameList()
oAuthProfilelist.each{
oAuthProfileName = oAuthProfilelist[i]
//log.info "oAuth Profile name is: $oAuthProfileName"if(oAuthProfileName == "$ENV"){
//log.info "oAuth Profile for $ENV is: $oAuthProfileName"
return
}
i++
}
//## Get Token Status ##//
oAuthProfile = project.getAuthRepository().getEntry("$oAuthProfileName")
TokenStatus = oAuthProfile.accessTokenStatus.toString()
log.info "Access Token Status for $oAuthProfileName is: $TokenStatus"
Thread.sleep(5000)//oAuthProfile.setClientID("$ClientID")
//oAuthProfile.setClientSecret("$ClientSecret")
//## Get Access Token from the server if expired ##//
if ((TokenStatus != 'RETRIEVED_FROM_SERVER') || (currentToken == oAuthProfile.getAccessToken())) {
log.info "Retrieving token from the auth server..."
oAuthClientFacade = new OltuOAuth2ClientFacade(TokenType.ACCESS)
oAuthClientFacade.requestAccessToken(oAuthProfile, true)
log.info "Access Token Status is " + oAuthProfile.accessTokenStatus
Thread.sleep(6000)
}
}thanks.
- Jainsoumya3 years agoContributor
New2API Hi
I am not sure where to write and use this code as token in only getting generated at browser , not able to capture it in token field
I am not sure you are getting my issue or not . We can connect over a call if its ok with you
- New2API3 years agoFrequent Contributor
Jainsoumya, probably you are right. I am not getting a full picture of your test configuration. However, from your Auth Manager snapshot it is clear that you are using an Authorization Profile to generate a token. Also, I am assuming that there is way to generate a token from Auth profile screen when it expires.
We architected our tests to use these three components of ReadyAPI - environment, AuthProfile and event handlers.
Environments comes handy if you want to run tests in different environments say QA, Dev, or Pre-PROD etc. Also, you can have different auth profiles for each environment and switching between different environments makes it easy. Finally event handlers to perform certain task based on the conditions such as authToken refresh before a service call.
please refer to attached snapshot to get an idea about event handlers usage.
Please note that you may have to run the test at testcase level or testsuite level in order to see this specific even to trigger.
Hope this helps.
- Jainsoumya3 years agoContributor
New2API Can we connect over a call . If its ok with you ?
- Jainsoumya3 years agoContributor
Auth token is not getting populated in the token field please note Its and OIDC connect .
I have added all the required fields and I have added steps in automation script , but when I click on get OpenID token , token is not getting populated in the field mentioned in GetID token .
I am new to readyapi so I am not aware of groovy script too
Please help
sonya_m I didnt get any solution from the incident which I have created for the same Case #00508484: OAuth Token Automation
- New2API3 years agoFrequent Contributor
Jainsoumya, call is not a problem. but how to reach you? (do not want to put my email/ph# here 🙂 )
- Jainsoumya3 years agoContributor
New2API Check message 🙂
Related Content
- 2 years ago
- 2 years ago
- 2 years ago