2
我想在使用OAUTH2身份驗證的api上使用RequestsLibrary。使用OAUTH2的Robot Framework API測試授權請求標頭
身份驗證通過OAUTH2提供給憑證提供給/ v1/authtoken端點。 後續對API的調用需要在http請求的「授權」標頭中將令牌包含爲「承載者」。
下面是測試用例。我得到的錯誤是: 401!= 200
憑據在jmeter中正常工作,並返回一個帳戶列表。但是,我無法獲得RF腳本的工作。任何幫助將不勝感激。
在腳本中,
- 登錄到控制檯
${accessToken}
返回訪問令牌:8ETFXTZOWQLrgsMj7c_KuCEeypdj-eO1r ... - 登錄到控制檯
${token}
回報:承載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()}
@桑迪普@Bryan你找到問題的答案,因爲我得到同樣的錯誤。好心分享答案 –
對不起,我不在。剛剛看到這個討論....我會試試這個。 –
是的,這現在似乎適用於我。謝謝。 但是,我純粹的生成auth2令牌的python方法是,我必須說得更簡潔! –