Forum Discussion

erarunmishra9's avatar
erarunmishra9
New Contributor
4 years ago

Validate authentication and create access token and use same to access another url in groovy

Hi all,
my Requirement is to validate login credentials against a url and will receive access token in response and use same access token to access another url and will get output string.
All the coding i need to done in groovy.
Please help.
thanks in advance.

1 Reply

  • Hi,

     

    Whilst I understand what you are trying to achieve, your request is still vague.  What have tried so far?  Is the token returned in the header or body of the request (I've done similar things where node of interest has been in both)? 

     

    Does the token form part of the URL for the second call, or just something passed in the body?

     

    Here's a rough example of something I use for some tests.  In short, I call a GET service to obtain a transaction id.  The transaction id is suffixed to the URL.  I then use this URL, with the transaction id, to call a POST service.

     

    // In this example, I've already called the get and I need to access the location property 
    // which I will then in in the post part.
    
    // Go and get the full URL, including token, from the GET call.
    def locationAndToken = testRunner.testCase.testSteps["first-call-test-step-name"].testRequest.responseHeaders["Location"];
    
    testRunner.testCase.testSteps["second-call-test-step-name"].properties["Endpoint"].value = locationAndToken;