Forum Discussion
aaronpliu
Frequent Contributor
If you have separate /token for oauth2, then you are able to create a scripts to dynamically get access_token.
FYI
import groovy.json.JsonSlurper
def data = new JsonSlurper().parseText(response) // get response of token
// set access token
def authProfileName = "LoginToken"
def project = testRunner.testCase.testSuite.project
def profile = project.getOAuth2ProfileContainer()
if (! (authProfileName in profile.getOAuth2ProfileList().name)) {
profile.addNewOAuth2Profile(authProfileName) // add new oauth2
}
def auth = profile.getProfileByName(authProfileName)
auth.setAccessToken(data.access_token) // set token
project.setAuthProfile(authProfileName) // applied in project level
Then you can select "LoginToken" for your request in test step or changed it in Auth manager
Thanks,
/Aaron
SoapuiTeay
4 years agoOccasional Contributor
Thanks Aaron. But it opens a web login page in soapui. I need to provide the credentials. Right now I am providing manually. I tried to automate using js but it didn't work. Do you have any other workarounds for this?
- aaronpliu4 years agoFrequent Contributor
Looks like you need to get token from web page.
So you are able to create a common test case with http request to simulate web page action to capture required login information.
Then using above-mentioned scripts to create an auth profile and each REST step to reference it.
If you have direct method or API (i.e. /token) to retrieve access token with credential, then no need to capture login credential like web page.
Not sure which type of authentication you use?
Thanks,
/Aaron
- SoapuiTeay4 years agoOccasional ContributorHi, I am making a rest call to authorization server which redirects to the Web login page. We need to provide the credentials and once the login is successful, we get the actress tokens.
- SoapuiTeay4 years agoOccasional ContributorWe have /token api but we need to pass Auth code in the request to this api which is generated once the login is successful.
Related Content
Recent Discussions
- 21 days ago