0

I wrote some code that gets an access token. When the code runs, a browser displays on the screen which contains the access token.

But when I try to get the access token and log it, a null string is being displayed. Also, I do not know if there is a way to force the browser to close using my code. Right now when I run this code, the browser window opens but I have to click on it to close it.

Could you please let me know what I am doing wrong ?

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("IMAGEN_Profile");
def clientSecret = testRunner.testCase.testSuite.getPropertyValue("Client_Secret")
def clientID = testRunner.testCase.testSuite.getPropertyValue("Client_ID")
oAuthProfile.setClientSecret(clientSecret);
oAuthProfile.setClientID(clientID);
log.info("Client Secret:"+clientSecret)
log.info("Client ID:"+clientID)

// the following code for getting new access token
def oAuthClientFacade = new OltuOAuth2ClientFacade(TokenType.ACCESS);
oAuthClientFacade.requestAccessToken(oAuthProfile, true);
def accessToken = oAuthProfile.getAccessToken()
testRunner.testCase.testSuite.setPropertyValue("Auth_Code",accessToken)
log.info("Access Token:"+accessToken)

1 Answers1

0

Unfortunately, the SoapUI documentation is rather terse.

Change your

oAuthClientFacade.requestAccessToken(oAuthProfile, true);

to

oAuthClientFacade.requestAccessToken(oAuthProfile, true, true);

source

SiKing
  • 10,003
  • 10
  • 39
  • 90
  • I tried that but it does not work. I am not getting the access token. it says null. Is your script in a event handler and how it was set up. – My Display Name May 03 '19 at 19:07
  • @MyDisplayName I followed the instructions at that link almost exactly, including setting things up as an event handler, and it works fine for me! – SiKing May 03 '19 at 23:05
  • @Siking : I tried the same script in CI/CD pipeline and it is failing. could you please help – sathiya Feb 26 '21 at 04:56