Applies to ReadyAPI 2.8, last modified on September 27, 2019

In the Automated Token editor, you can use scripts to automate retrieval of OAuth 2.0 tokens. You can use JavaScript to create interactions with authorization pages provided by the authorization server.

How It Works

For each page involved in the authorization process, you add the corresponding field in the editor. In each field, you place the JavaScript code that performs the authorization actions required for that page.

The script specified in a field will run when the page is open in the browser. You can find an example of this script in the OAuth Automation Example topic.

Note: During the authorization process, the pages are called in the specified order. ReadyAPI neither recognizes the called pages nor does it interact with them. To ensure that you are on a proper page, use scripts.

In the Auth Manager

The Automated Token editor becomes available on the Automation Scripts tab after you select an OAuth 2.0 profile in the Auth Repository:

Auth manager

Click the image to enlarge it.

On the Auth Tab

In requests, you can access the Automated Token editor from the Auth inspector:

Auth manager

Click the image to enlarge it.

  1. Select an OAuth 2.0 Profile.

  2. Click Get Token.

  3. Click Automation.

Automating Token Retrieval on Request

By default, ReadyAPI does not check if a token has expired even if automated retrieval is enabled. You can use Groovy scripts to check if a token is up-to-date and retrieve a new token, if necessary. For this purpose, call the requestAccessToken method and specify the consoleMode parameter as described in the Automating Token Retrieval Example topic.

On headless machines where the browser window is inaccessible, you can use the same approach as described above. However, there are some things you must do first:

  • Install and run any X Server.

  • Specify the display number for your X Server (see the documentation of your X Server).

  • Open the testrunner.sh file in a text editor and add the following line:

    export DISPLAY=<ip>:<index>

    ip

    The IP address of the X Server.

    index

    The display number you have specified.

To automate token retrieval with Docker using the approach described above, do the following:

  • Install and run any X Server (for example, VcXsrv Windows X Server).

    Note: If you use Docker for Linux, you may skip this step, as your machine probably already has an X Server.
  • Specify the display number for your X Server (see the documentation of your X Server).

  • You'll have to use a special version of the Docker image that has the <version>-ui tag, so pull this image:

    docker pull smartbear/ready-api-soapui-testrunner:2.6.0-ui
  • When you run the container, add the following parameter to the command line:

    -e DISPLAY=<ip>:<index>

    ip

    The IP address of the X Server.

    index

    The display number you have specified.

    Command line example

See Also

Using the Automated Token Script Editor
OAuth Automation Example
Automating Token Retrieval

Highlight search results