Forum Discussion
- PrathapRFrequent Contributor
Hey,
I use oAuth2.0 token (Which is set and used at Auth Manager at Project level ), I added below code to Test Suite setup script, it automatically pulls new token every time it runs.
// Import the required classes import com.eviware.soapui.impl.rest.actions.oauth.OltuOAuth2ClientFacade; import com.eviware.soapui.support.editor.inspectors.auth.TokenType; import com.eviware.soapui.model.support.ModelSupport; // Get a project def project = ModelSupport.getModelItemProject(context.getModelItem()); // Get the needed authorization profile def authProfile = project.getAuthRepository().getEntry("YourOAUTHProfileName"); //Create a facade object def tokenType = TokenType.ACCESS; def oAuthFacade = new OltuOAuth2ClientFacade(tokenType); // Request an access token in headless mode and assign it to the authorization profile we got earlier oAuthFacade.requestAccessToken(authProfile, true, true); // Access token retrieval may take time, so we need to pause the execution for 3 seconds to finish it. You may increase this value if needed. sleep(3000); // Posts a new token to the script log log.info("Set new token OAuth2.0: " + authProfile.getAccessToken());
- nmraoChampion Level 3
Try this library and sample codes available in the link below
https://github.com/jwagenleitner/groovy-wslite
First the library has to be built locally and then copy the library under READYAPI_HOME/bin/ext directory and restart the tool.
If you don't want to build the library locally, then you can download the library from maven repo
https://mvnrepository.com/artifact/com.github.groovy-wslite/groovy-wslite
Related Content
- 6 years ago
- 5 years ago