ReadyAPI: Using automated Authorization from Auth Repository
- 5 years ago
AAB, I believe the script you are looking is under "Calling the Automated Retreival Procedure".
// 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;
// Set up variables
def project = ModelSupport.getModelItemProject(context.getModelItem());
def authProfile = project.getAuthRepository().getEntry("OAuth 2");
def oldToken = authProfile.getAccessToken();
def tokenType = TokenType.ACCESS;
// Create a facade object
def oAuthFacade = new OltuOAuth2ClientFacade(tokenType);
// Request an access token in headless mode
oAuthFacade.requestAccessToken(authProfile, true, true);
// Wait until the access token gets updated
while(oldToken == authProfile.getAccessToken()) {
}
//The sleep method can be used instead of a while loop
//sleep(3000);
// Post the info to the log
log.info("Set new token: " + authProfile.getAccessToken());