mik*_*ana 3 soap oauth google-api
我目前正在尝试通过Chrome扩展程序访问Google服务。我的理解是,对于JS应用,Google首选的身份验证机制是OAuth。我的应用当前已通过OAuth成功验证了该服务。
查询服务的首选机制是通过SOAP。但是,SOAP具有它自己的“身份验证令牌”概念,该概念设置在XML主体中。我没有每个Google文档都可以使用的旧式“ ClientLogin”令牌。
如何使用OAuth认证的访问令牌运行SOAP查询?还是应该使用其他机制进行查询或认证?
回答自己:
通过普通机制(即在JS中)对OAuth进行身份验证:
var oauth = ChromeExOAuth.initBackgroundPage({
'request_url': 'https://www.google.com/accounts/OAuthGetRequestToken',
'authorize_url': 'https://www.google.com/accounts/OAuthAuthorizeToken',
'access_url': 'https://www.google.com/accounts/OAuthGetAccessToken',
'consumer_key': 'anonymous',
'consumer_secret': 'anonymous',
'scope': 'https://domain_for_your_api/',
'app_name': 'Your app name'
});
Run Code Online (Sandbox Code Playgroud)
然后验证并运行您的SOAP请求作为回调:
function authenticateAndGetAlerts() {
oauth.authorize(runMyRequest);
}
Run Code Online (Sandbox Code Playgroud)
SOAP标头是所记录内容的较小版本,省略了仅ClientLogin API必需的字段。
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://adwords.google.com/api/adwords/mcm/v201008" xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201008" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Header>
<ns1:RequestHeader xsi:type="ns2:RequestHeader">
<ns2:developerToken>Your developer token</ns2:developerToken>
<ns2:userAgent>Your app name</ns2:userAgent>
</ns1:RequestHeader>
</SOAP-ENV:Header>
Run Code Online (Sandbox Code Playgroud)
身体是正常的。
然后使用适当的方法(JS中的oauth.sendSignedRequest)对此进行发布,该方法会将必需的OAuth字段添加到查询字符串中:
var request = {
'method': 'POST',
'body': soapenvelope
};
oauth.sendSignedRequest(url, callback, request);
Run Code Online (Sandbox Code Playgroud)
做完了 如果您需要手动进行查询,而不是使用诸如sendSignedRequest之类的查询,则如下所示:
servicename.google.com/where/your/service/lives?oauth_consumer_key=anonymous&oauth_nonce=something&oauth_signature=something&oauth_signature_method=HMAC-SHA1&oauth_timestamp=something&oauth_token=something
Run Code Online (Sandbox Code Playgroud)
TLDR:查询字符串中的OAuth,忽略SOAP标头中的所有身份验证信息。
| 归档时间: |
|
| 查看次数: |
10600 次 |
| 最近记录: |