Forum Discussion

Jagruuti's avatar
Jagruuti
Contributor
5 years ago

How to extract the access token from the 'Auth' tab and transfer it to the other requests in header?

I want to get the generated Access Token from the Auth tab and use it as a property for other tests. (Require to pass the access Tokens as the header for all the test steps). I want to avoid doing it manually for all the test steps.

Is it possible for me to achieve that?

Note: The access Tokens are not generated in the response. I'm using OAuth 2.0 and the tokens are getting generated in the Auth Tab.

 

Attached is the screenshot for more reference.

  • Hi sonya_m,

     

    Support Team has provided with the answer 🙂

     

    While using OAuth 2 flow, you need to select the checkbox of 'Use Authorization Header' as shown in the attached screenshot. Then, you don't need to add the token in the Headers tab Ex. Authorization: Bearer [Access Token].  After that, you can use the Auth Manager and select the respective OAuth 2 profile for your requests.

     

    Thank you,

    Jagruuti

     

  • richie's avatar
    richie
    Community Hero
    Hi Jagruuti,

    Apologies for my late reply, i got sidetracked with some personal stuff.

    Unless someone else has a nifty idea, i think you have 2 choices here. As the access token isn't available via a request/response's raw request/response content you need another option.
    I tested a system that used OAuth v2.0 last year, but it had been customised so much that the embedded OAuth functionality in ReadyAPI! didn't work so i had to setup all the individual requests that comprise the back and forth that makes up the OAuth v2.0 auth which allowed me to do what you need to extract the access token to save it to a property. This option would allow you to do what you need, but it did take a lot of effort to automate the whole thing. Obviously i can understand how you wouldnt want to adopt this approach considering youve already got your OAuth setup already.

    2nd option i can think of is if you raise a support call with Smartbear and see if they can advise how to extract the token value (its got to be persisted in a variable somewhere under the covers, right?) considering it doesnt look like anyone on the forum can help at this point....??

    Sorry i cant be of more help,

    Rich
    • Jagruuti's avatar
      Jagruuti
      Contributor

      Hi richie,

       

      Thank you so much for your reply!

      One more thing, you have mentioned that you have set up all the individual requests that comprise the back and forth which helped you to extract the access token and save it in a property. How did you do that?

      Though I have the OAuth setup already, I would like to automate the below steps sequentially.

      1)The clicking of 'Get Access Token' Button

      2) Entering the login credentials on the login page of application.

      3) Extracting the verification code from outlook and entering on the next page after login.

      4) Extracting the access token and adding it in the header.

       

      And yes I will try the second option too.

       

      Regards,

      Jagruuti

      • sonya_m's avatar
        sonya_m
        SmartBear Alumni (Retired)

        Hi Jagruuti , I see you are working with the Support Team on this - please let us know when you get the solution! Thank you.

    • Jagruuti's avatar
      Jagruuti
      Contributor

      Hi nmrao,

       

      I tried automating it also, I was getting an error as shown in the 'Script failure error' attachment.  Also please find the below code snippet in the other attachment.

      I tried using the below code, which I think was correct. Or can you explain me which code should be added so that I can automate the manually generated token process? or is this the application related issue? Because manually the token was getting created.

       

      Also, I discussed this with one of the developer in our team, he suggests this might be a configuration issue at the SOAP UI end while doing automation. 

       

      Regards,

      Jagruuti

       

      • richie's avatar
        richie
        Community Hero
        Hi Jagruuti,

        Im getting a 404 when i try downloading the .png files you attached.

        Can you please either reattach or embed the details directly into your post instead?

        Also. Just so we're nice and clear. You have your OAuth v2.0 setup correctly via the Auth tab on your resource or method and you want to extract the token value from this?

        Nice one,

        Rich