Forum Discussion
Hi, I am using the following code to set the token automatically. You can set it as a test suite property variable and try it out.
import com.eviware.soapui.impl.rest.actions.oauth.OltuOAuth2AzureClientFacade;
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("YOUR AUTHORIZATION PROFILE NAME");
//Create a facade object
def tokenType = TokenType.ACCESS;
def oAuthFacade = new OltuOAuth2AzureClientFacade(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.
sleep(3000);
// Posts a new token to the script log
log.info("Set new token: " + authProfile.getAccessToken());
Related Content
- 12 months ago
Recent Discussions
- 2 days ago