我试图在使用OAUTH2身份验证的api上使用RequestsLibrary .
通过OAUTH2进行身份验证,并将凭据提供给/ v1 / authtoken endpoints . 对APÍ的后续调用需要将令牌作为“承载”包含在http请求的“授权”头中 .
以下是测试用例 . 我得到的错误是:401!= 200
凭证在jmeter中正常工作,并返回一个帐户列表 . 但是,我无法使RF脚本工作 . 任何帮助将不胜感激 .
在脚本中,
-
登录到控制台
${accessToken}
返回访问令牌:8ETFXTZOWQLrgsMj7c_KuCEeypdj-eO1r ... -
登录到控制台
${token}
返回: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()}
2 回答
我正在使用OAuth 2.0身份验证以及我的salesforce自动化 .
My first answer would be to skip client based authentication and switch to username/password based authentication
如果您使用基于客户端或基于Web的身份验证,则会有一个登录屏幕,用户将使用该屏幕输入用户名/密码来授权应用程序代表其发送请求 . 请查看这些页面以获取更多信息,因为它们主要讨论使用刷新令牌或完全跳过用户提示 .
Why does Google OAuth2 re-ask user for permission when i send them to auth url again
https://salesforce.stackexchange.com/questions/785/authenticate-3rd-party-application-with-oauth2
我正在使用的API无法跳过OAuth2 . 所以我不得不继续使用OAuth2为了回应Sandeep的问题,我也遇到了同样的问题 . 在您获得请求之前,您可能必须在分配Authorization = $ 后创建会话....请尝试以下一次
另外,它的帮助方式如下:
希望能帮助到你! :)