Rest request oAuth2 token POST


#21

Got solution for this.

‘Get response’
def response = WS.sendRequest(findTestObject(‘EMP/EMP Login’))

‘Verify if login was successfully’
WS.verifyElementPropertyValue(response, ‘result’, ‘Successful’)

WS.verifyResponseStatusCode(response, 200)

def slurper = new groovy.json.JsonSlurper()

def result1 = slurper.parseText(response.getResponseBodyContent())

println(result1)

‘Get token’
def token1 = result1.‘token’
println(token1)

‘Scope to a project’
RequestObject ScopeToProject = findTestObject(‘EMP/GetAllTenants’)

‘Create new ArrayList’
ArrayList HTTPHeader = new ArrayList()

‘Send token in HTTP header’
HTTPHeader.add(new TestObjectProperty(‘Authorization’, ConditionType.EQUALS,'Bearer ’ +token1))

‘Set that token’
ScopeToProject.setHttpHeaderProperties(HTTPHeader)

‘Get response text’
response = WS.sendRequest(ScopeToProject)

‘Verify if scope to project was successfull’

WS.verifyResponseStatusCode(response, 200)


#22

@sudharani.suggu

Are you writing the above code in a test case? Or the Object Request repository? It seems the Object Request repository is almost becoming useless since we can’t authorize easily without lines of code. It also won’t accept variables in the Headers, Body so we can at least save them to a file and call them from there.


#23

Hi @Anuradha,

I am stuck with exactly the same problem, where I have to request the token and update the header. Could you please share your code.

Thank you in advance

Regards,
Goutham


#24

Hi Team ,
I am facing an issue with Request Token .If hit the Request Token the Authorized Bearer only Create not an Lengthy refresh token (eg : eyJjdHkiOiJKV1QiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiUlNBLU9BRVAtMjU2In0 ) . only Bear is created . but Postman its creates . whats the issue.

and the refresh token will expires on 1 hrs . how to get using automation. could you please any one.

Thanks


#25

I have the same problem when trying to generate a token , It works when I use the same parameters with PostMan but With Katalon I have a 500 Internal Error !!


#26

Hi @gabsi.manel,
What is your input for generating a token? For confidentiality reason, you can email us that info.
Regards.


#29

Which email ?


#30

It works . I Added manually in HTTP header the Authorizarion Values for the Bearer and Client-ID