Forum Discussion

catshout's avatar
catshout
Frequent Visitor
5 years ago

Capture ID Token from an OAuth2 Access Token Respones (SoapUI 5.6.0)

Hi all,

I've configured OAuth2 for a REST project. When requesting an access token I'm passing the "openid" scope. The response contains normally the access token, the refresh token and the ID token. How can I capture the ID token from the response?

Best - Gerald

  • Hi,

    Where I need to 'grab' a value from a service response, I tend to use a Groovy script.  You can access values in a response by specifying the test step and response value of interest.

     

    For example, in your test, you have a test step to call a web service.  After that step, add a Groovy script test step.  In the licensed version (not sure about the open source version), you can right-click in the Groovy script step and a context menu pops up.  On this menu, select 'get data'.  Get data allows you to select a test step and you can then drill-down to the value of interest.  Once you find the value and you click 'OK', the Groovy script to access the value of interest is displayed.  You can then report this value, save it somewhere, or add it to Custom Properties for use later.

     

    If your SoapUI does not have the 'get data', then it's a little more tricky.  You will need to use context.expand...

    def id = context.expand( '${yourTestStep#Response#declare namespace ns1=\'urn:yourOrder:domain:1\'; //ns1:requestResponse[1]/ns1:requestResult[1]/ns1:someDto[1]/ns1:id[1]}' )

    The above creates a variable called id which looks in the test step and uses XPath to drill down to the response tree and ultimately the id.  The above is just an example.  You'll need to look at your response and the namespaces to be able to use XPath.

     

    Without a response example in your original question, it's difficult to help further.