How to get access token dynamically using code

Please help…

Hi @gopabandhu.patra,
What Grant Type do you want to use?

It is “Implicit”

Hi @gopabandhu.patra,
Getting access token for implicit grant type is a little bit tedious, and involves Web UI testing. Is it feasible from your side to use another grant type, such as Password credentials?

Am checking for Password credential Grant type… Please recommend how can i automate if my developer will provide me

Hello My developer denied to change the Grant type except Implicit due to security reason.
I am using above code to get the Token value from the excell sheet (where i am getting token using postman tool and storing in excel), before executing my test suite, i update the token and using it for authentication.
I hope the steps are correct or do we have any inbuild jar file available so that i can use it and get the token dynamically if Grant type is Implicit.

Hi @gopabandhu.patra,
Your solution is acceptable as long as you don’t mind manually getting the access token and storing it for Katalon retrieval every time you execute your test suite. For a more dynamic solution, please refer to the sample project attached for how to get the access token without manual intervention. Of course, you have to fine-tune the project to suite your needs, and you have to accept some automation code that involves Web UI testing.OAuth2_Implicit_1.zip (48.6 KB)

Dear Huynguyen, I have a problem that my redirect URL where token present is a transit URL basically. After entering user name and password, it is successfully loging in and redirecting a different URL. However, I can see in transit from Username password page to successful login page the URL is having token information.
How can i capture transit URL?.

Hi @gopabandhu.patra,
Have you tried WebUI.getUrl()?

YES…already but transit URL, unable to capture… It is just capturing the last redirect URL.

Hi @gopabandhu.patra,
Can you share with us the transit URL?

https://qamyevents.XXX.com/callback#access_token=eyJhbGciOiJSUzI1NiIsImtpZCI6Ijc3Q0EwNDJBRUIzOTIzRTA3QTUyNzI0MEFCQTlFQkVCMTY2N0YzNUIiLCJ0eXAiOiJKV1QiLCJ4NXQiOiJkOG9FS3VzNUktQjZVbkpBcTZucjZ4Wm44MXMifQ.eyJuYmYiOjE1OTY0MTYyMDUsImV4cCI6MTU5NjQxODAwNSwiaXNzIjoiaHR0cHM6Ly9pZHN2Yy5wZXRyb25hcy5jb20iLCJhdWQiOlsiaHR0cHM6Ly9pZHN2Yy5wZXRyb25hcy5jb20vcmVzb3VyY2VzIiwibXlmaWxlYXBpIiwibXlldmVudHNhcGl3ZWIiXSwiY2xpZW50X2lkIjoiZm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4SJUiCHbAlabCfiUGedztckoH5q_Li3U63cOAJK9DDRzsKwsPW_gsT7Ay3r83iB-zduP1uEqFepKX2o9_Cc58VrmR9t8lRA&token_type=Bearer&expires_in=1800&scope=myfileapi%20myeventsapiweb

I have added XXX which is company name…

And the last redirect url doesn’t have the access token?

YES…Last URL doesnt have access token

Can you help me on this how can i capture transit URL info?. really want to wind up the automation manual token info generation.

Hi @gopabandhu.patra,
Instead of using WebUI.getUrl(), can you try WebUI.executeJavaScript(‘return window.document.referrer’, null) to get the immediate URL?

WebUI.click(findTestObject(‘Object Repository/Page_Sign In/span_Sign in’))

String redirectUrl=WebUI.executeJavaScript(“return window.document.referrer;”, null)

println “ORIGINAL…”+redirectUrl

Did it but it is not capturing transit URL…

Any response please??

Hi @gopabandhu.patra,
Can you share a video that capture the automation process to login for OAuth2 access token?