rickypc / robotframework-extendedrequestslibrary

Extended HTTP client testing library for Robot Framework with OAuth2 support
https://pypi.python.org/pypi/robotframework-extendedrequestslibrary
GNU Affero General Public License v3.0
8 stars 4 forks source link

Robot Framework api test with OAUTH2 Authorization Request Header #3

Open sandeepvaidya opened 7 years ago

sandeepvaidya commented 7 years ago

I am trying to use the RequestsLibrary on an api thats using the OAUTH2 authentication.

Authentication is via OAUTH2 with credentials being supplied to the /v1/authtoken endpoint. Subsequent calls to the APÍ need to have the token included as a ‘bearer’ in the ‘Authorization’ header of the http requests.

So below is the test case. The error I am getting is: 401 != 200

The credentials work ok in jmeter and a list of accounts is returned. However, I am not able to get the RF script work. Any help will be appreciated. In the script, 1) Log to Console ${accessToken} returns the access token: 8ETFXTZOWQLrgsMj7c_KuCEeypdj-eO1r...

2) Log to Console ${token} returns: Bearer 8ETFXTZOWQLrgsMj7c_KuCEeypdj-eO1r...

Test Cases Get authToken Create Session hook http://xxxx.azurewebsites.net verify=${True} ${data}= Create Dictionary grant_type=client_credentials client_id=yyy-zzzz client_secret=xxxxxxxxxxxxxxx ${headers}= Create Dictionary Content-Type=application/x-www-form-urlencoded ${resp}= post request hook /v1/authtoken data=${data} headers=${headers} Should Be Equal As Strings ${resp.status_code} 200 Dictionary Should Contain Value ${resp.json()} bearer ${accessToken}= evaluate $resp.json().get("access_token") Log to Console ${accessToken} ${Bearer}= Set Variable Bearer ${token}= catenate Bearer ${accessToken} Log to Console ${token} ${headers}= Create Dictionary Authorization=${token} ${resp1}= get request hook /v1/integration/accounts headers=${headers} Should Be Equal As Strings ${resp1.status_code} 200

Log to Console ${resp1.json()}

sandeepvaidya commented 7 years ago

When I use the ExtendedRequestsLibrary to do the same

Create Client OAuth2 Session client https://xxxx-staging.azurewebsites.net/v1/authtoken base_url=hhttps://xxxx-staging.azurewebsites.net

I get a "MissingTokenError: (missing_token) Missing access token parameter." error. Where does the access token parameter go ?

swapnil120890 commented 7 years ago

Hey you got this resolved? I have the same issue

sandeepvaidya commented 7 years ago

No. I wrote a python method to generate the token. What are you doing and what is the error ?

swapnil120890 commented 7 years ago

I get this error 20170921 07:26:11.917 : FAIL : MissingTokenError: (missing_token) Missing access token parameter.

I am trying RF for API testing,I am new to this hope script is correct i get the above error Create Client OAuth2 Session QA http://XXXQAEnv:XXX!23@52.30.208.79/api/oauth/token mobile_android secret base_url=http://52.30.208.79 ${var} = Post Request QA /api/oauth/token json=${"tokens":"access_token"} Log ${var}

sandeepvaidya commented 7 years ago

Are you able to generate a token by some other means? E.g.: python requests ? Try to isolate the problem

swapnil120890 commented 7 years ago

But token is something that should be returned back? I tested on postman it works fine.In RF it gives me the above error.

sandeepvaidya commented 7 years ago

Oauth2 token generation is implementation specific. The error I was getting was in the ExtendedRequestsLibrary which is an extended HTTP client library for Robot Framework with OAuth2.

If your POST is not working for you in Robot Framework but it works in another framework, I think its you post thats the problem.

swapnil120890 commented 7 years ago

I am also using extended requests library.Anyways thanks for your inputs i will try to figure it out.

Divya1711 commented 4 years ago

I get this error 20170921 07:26:11.917 : FAIL : MissingTokenError: (missing_token) Missing access token parameter.

I am trying RF for API testing,I am new to this hope script is correct i get the above error Create Client OAuth2 Session QA http://XXXQAEnv:XXX!23@52.30.208.79/api/oauth/token mobile_android secret base_url=http://52.30.208.79 ${var} = Post Request QA /api/oauth/token json=${"tokens":"access_token"} Log ${var}

@swapnil120890 : Hey got this resolved ? I am facing same issue with RobotFramewok.

Divya1711 commented 4 years ago

@sandeepvaidya : r u able to resolve the above issue. I too facing same issue. please help me if u were able to solve it. Thanks

sandeepvaidya commented 4 years ago

Yes, i was able to make this work. Contact me directly.


From: Divya1711 notifications@github.com Sent: Wednesday 24 June 2020 13:24 To: rickypc/robotframework-extendedrequestslibrary robotframework-extendedrequestslibrary@noreply.github.com Cc: sandeepvaidya sandeep_vaidya@hotmail.com; Mention mention@noreply.github.com Subject: Re: [rickypc/robotframework-extendedrequestslibrary] Robot Framework api test with OAUTH2 Authorization Request Header (#3)

@sandeepvaidyahttps://github.com/sandeepvaidya : r u able to resolve the above issue. I too facing same issue. please help me if u were able to solve it. Thanks

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/rickypc/robotframework-extendedrequestslibrary/issues/3#issuecomment-648787577, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABRZCFNAQLCAHZWPKZVYL23RYHV63ANCNFSM4C6XASPA.

Divya1711 commented 4 years ago

@sandeepvaidya i have mailed you. could you please reply to it.

pradnyaphadale commented 4 years ago

i am trying to collect request token by connecting to API. But it gives me "MissingTokenError: (missing_token) Missing access token parameter." error. If anybody found solution could you please share with me?.