Automating OAuth 2 authentication and consent
The Get Token OAuth 2 functionality in SoapUI has the ability to run JavaScript to automatically authenticate and grant permissions (consent) during the browser-based interaction with the Authorization Server. Assuming you're happy to provide your credentials to the script, this could be useful if unattended authentication is required for your tests. This recipe briefly shows how to do this for the previous Gmail example.
Getting ready
This recipe assumes you've completed the previous recipe. In any case, you can find the completed SoapUI project GoogleOAuth2
in the chapter 8
samples.
How to do it...
We just need to add the automation JavaScript to input credentials and submit on the first screen (login screen). Then, when the second screen (consent) is displayed, click on Accept:
Under the Auth tab, open the Get Token window and click on Automation. Then, enter the following scripts, as shown in the screenshot:
Edit your Gmail account and password...