Forum Discussion
6 Replies
- nmrao
Champion Level 2
Have you tried Property Expansion?- New2APIFrequent Contributor
Thanks nmrao for the suggestion. I was able to retrieve access token using global properties.
I was wondering if you could help me or show some pointers (apis) to automate this using groovy? or Java script.
thanks!
Hi New2API,
To change the credentials you have set in the authorization profile (for the Client Credentials Grant type) you can use the following script in the Groovy Test Step:
import com.eviware.soapui.impl.rest.actions.oauth.OltuOAuth2ClientFacade import com.eviware.soapui.support.editor.inspectors.auth.TokenType def project = context.getTestCase().getTestSuite().getProject(); def oAuthProfile = project.getAuthRepository().getEntry("YourAuthProfile"); oAuthProfile.setClientSecret("Secret"); oAuthProfile.setClientID("Identification"); // the following code for getting new access token def oAuthClientFacade = new OltuOAuth2ClientFacade(TokenType.ACCESS); oAuthClientFacade.requestAccessToken(oAuthProfile, true);
- spoot99Senior Member
Hi There,
I was looking for the exact same answer as the question listed above. Thanks a lot for the reply, it gave me direction to look further.
I was able to create a GroovyScript and parametrize the Auth Entry.
""""
import com.eviware.soapui.impl.rest.actions.oauth.OltuOAuth2ClientFacade
import com.eviware.soapui.support.editor.inspectors.auth.TokenTypedef project = context.getTestCase().getTestSuite().getProject();
def oAuthProfile = project.getAuthRepository().getEntry("Name");
oAuthProfile.setClientID("client id")
oAuthProfile.setClientSecret("client secret")
oAuthProfile.setScope("scope")
oAuthProfile.setAuthorizationURI("authorization URL" )
oAuthProfile.setAccessTokenURI("AccessToken URL" )
oAuthProfile.setRedirectURI("Redirect URL" )oAuthProfile.setAutomationJavaScripts(["AutomationPage1", "AutomationPage2"])
//Run the Entry
def oAuthClientFacade = new OltuOAuth2ClientFacade(TokenType.ACCESS);
oAuthClientFacade.requestAccessToken(oAuthProfile, true);""""
Best of luck!