Forum Discussion

msalvador's avatar
msalvador
Frequent Contributor
3 years ago

Oauth2 bearer

Hi guys,

first of all, I hope to explain the issue in the correct way.

I have 2 calls, one to retreive the jwt, the other one to do forge.

In the second one in Aouth panel in  Access token field I have to put the access token from the first call.

If in Access token field I put directly the value, works, but if I try to get from the response it doesn't.

Attachment describe better the scenario

  • I solved with groovy script.

    Below the solution.

     

    import com.eviware.soapui.config.AuthEntryTypeConfig

    def authProfileName = "Bearer"
    def project = testRunner.getTestCase().getTestSuite().getProject()
    def authProfile = project.getAuthRepository().getEntry(authProfileName)
    //authProfile.setDomain ("newDomain")
    def accessToken = context.expand( '${Verify Token 2 - token - v4 Generazione JWT per Forge token#Response#$[\'accessToken\']}' )
    authProfile.setAccessToken(accessToken)
    //Set to true for pre-emptive authentication
    //Set to false for using global preference
    //authProfile.setPreemptive(true)

    def step = testRunner.testCase.getTestStepByName("Verify Forge - forge token - v4").getHttpRequest()
    step.setSelectedAuthProfile(authProfileName)

  • msalvador's avatar
    msalvador
    Frequent Contributor

    I solved with groovy script.

    Below the solution.

     

    import com.eviware.soapui.config.AuthEntryTypeConfig

    def authProfileName = "Bearer"
    def project = testRunner.getTestCase().getTestSuite().getProject()
    def authProfile = project.getAuthRepository().getEntry(authProfileName)
    //authProfile.setDomain ("newDomain")
    def accessToken = context.expand( '${Verify Token 2 - token - v4 Generazione JWT per Forge token#Response#$[\'accessToken\']}' )
    authProfile.setAccessToken(accessToken)
    //Set to true for pre-emptive authentication
    //Set to false for using global preference
    //authProfile.setPreemptive(true)

    def step = testRunner.testCase.getTestStepByName("Verify Forge - forge token - v4").getHttpRequest()
    step.setSelectedAuthProfile(authProfileName)

  • Hi,

    I would check that the previous request is sent. If the first call is not sent, there is no node available to pass into the Access token field, therefor it would appear null. 

  • msalvador's avatar
    msalvador
    Frequent Contributor

    Hi mattb,

    If you see pict. token2.png, response field is not null.

    In forge.png, I try to pass Access token field the value caming from token2.png.

    Always in forge.png if you see the request Authorization: Bearer $['accessToken']

    so $['accessToken'] seems do not contain value but is a string