Forum Discussion

telong's avatar
telong
New Contributor
8 years ago
Solved

OATH2 Authentication - can "get ID Token" be automated in testing?

I have oath2 authentication configured and have setup correct automation scripts. It works perfectly for setting up the access token.  Furthermore, I can access this token within a groovy script by t...
  • telong's avatar
    8 years ago

    Found a solution from SmartBear.  Posting to help others.  Here is the reply... worked perfectly for me.  Put this code into a groovy step.  I had to modify the profileName retrieval line but it worked exactly as-is otherwise.

     

    --------------  Begin Code snippet ----------------

     

    import com.eviware.soapui.support.editor.inspectors.auth.TokenType
    import com.eviware.soapui.impl.rest.actions.oauth.OltuOAuth2ClientFacade

    def authContainer = testRunner.testCase.testSuite.project.OAuth2ProfileContainer
    // Get OAuth2 profile name
    def profileName = context.expand( '${#Project#profileName}' )
    def authProfile = authContainer.getProfileByName(profileName)

    def clientFacade = new OltuOAuth2ClientFacade(TokenType.ID)  //TokenType.ID gets the ID token
    clientFacade.requestAccessToken(authProfile, true)
    def accessToken = authProfile.getAccessToken()

    -------------------  End code snippet -----------------------

     

    Additionally, there is this for just the access token (From SmartBear):

    You can get the access token by using  the Groovy script above and replacing def clientFacade = new OltuOAuth2ClientFacade(TokenType.ID) with def clientFacade = new OltuOAuth2ClientFacade(TokenType BEARER) to get the access token instead of the id token.