使用OAuth访问令牌访问SOAP服务?
我目前正试图通过Chrome扩展访问Google服务。我的理解是,对于JS应用程序,Google首选的身份验证机制是OAuth。我的应用程序目前已通过OAuth成功验证该服务 查询服务的首选机制是通过SOAP。但是,SOAP有自己的“身份验证令牌”概念,这是在XML主体中设置的。我没有一个旧式的“ClientLogin”令牌可以在谷歌的文档中使用 如何使用OAuth身份验证的访问令牌运行SOAP查询?还是应该使用不同的机制来查询或验证?回答自己: 通过正常机制(即在JS中)向OAuth进行身份验证:使用OAuth访问令牌访问SOAP服务?,soap,oauth,google-api,Soap,Oauth,Google Api,我目前正试图通过Chrome扩展访问Google服务。我的理解是,对于JS应用程序,Google首选的身份验证机制是OAuth。我的应用程序目前已通过OAuth成功验证该服务 查询服务的首选机制是通过SOAP。但是,SOAP有自己的“身份验证令牌”概念,这是在XML主体中设置的。我没有一个旧式的“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'
});
然后进行身份验证并将SOAP请求作为回调运行:
function authenticateAndGetAlerts() {
oauth.authorize(runMyRequest);
}
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>
完成了。如果您需要手动执行查询,而不是使用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
TLDR:OAuth在查询字符串中,省略SOAP头中的所有身份验证信息
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