灵动创新 Unimarketing 邮件营销 EDM

OAuth 相关说明

1. OAuth 授权方法是一种开放式授权协议,在桌面应用程序和基于网络的应用程序中使用。 OAuth 可让应用程序获取访问令牌,而无需处理用户的凭据。 您必须使用安全证书注册应用程序,才能使用 OAuth。 OAuth 网站( http://oauth.net/)包含 OAuth 的最常见使用情况的清晰说明。 下列情况下请考虑使用 OAuth:
您要开发的应用程序是支持 OAuth 的网站。
您要开发针对各种不同客户端的应用程序(安装版、网络版、移动版)。
您要在使用多家提供商的多种服务的环境中开发应用程序。

2. OAuth 关键术语
术语 定义
Service Provider A web application that allows access via OAuth. For example, Google or MySpace
User An individual who has an account with the service provider, for whom the service provider might have data that could be accessed via OAuth. For example, a gadget might access a user's Google calendar data via OAuth.
Consumer A website or application that uses OAuth to access the service provider on behalf of the user. In this context, a gadget that uses OAuth to access a user's data would be the consumer.
Protected Resources Data controlled by the Service Provider, which the consumer (gadget) can access through authentication.
Container A container is an OpenSocial environment in which gadgets are embedded. For example, iGoogle is a container. The container is responsible for managing the gadgets' layout and controls, as well as for supporting various functionality on behalf of the gadgets. An OAuth gadget can only run in a container that supports OAuth. If a gadget uses OAuth, it is actually the container that executes the OAuth protocol on behalf of the gadget by handling all the digital signing required by the protocol
Consumer Key A value used by the gadget to identify itself to the service provider. This corresponds to the oauth_consumer_key parameter. See the OAuth spec for details.
Consumer Secret A secret used by the gadget to establish ownership of the consumer key.
Request Token A value used by the gadget to obtain authorization from the user, and exchanged for an access token.
Access Token A value used by the gadget to gain access to the protected resources on behalf of the user, instead of using the user’s service provider credentials.
Token Secret A secret used by the gadget to establish ownership of a given token.
中文参考地址 http://code.google.com/intl/zh-CN/apis/gadgets/docs/oauth.html

3. OAuth 操作流程图

( Oauth demo(java) 下载)
将应用程序放入Tomcat下,启动服务。 访问地址:http://localhost:8080/ApiClient/getAccessTokenServlet.do?url=go_to_oauth
OAuth Library http://code.google.com/p/oauth/
认证流程及访问资源流程
  • 第一步:获取未授权的 Request Token(请求URL: http://services.unimarketing.com.cn/auth/request_token)
    • 请求参数 意 义
      oauth_consumer_key OAuth Consumer Key
      oauth_signature_method 签名方法,使用HMAC-SHA1
      oauth_signature 签名值
      oauth_timestamp 时间戳
      oauth_nonce 单次值,随机字符串,防止重复提交
  • 第二步:请求用户授权 Request Token(请求URL:http://services.unimarketing.com.cn/auth/authorize)
    • 请求参数 意 义
      oauth_token 上一步中获得的Request Token
      oauth_callback 如果包含这个参数,认证成功后浏览器会被重定向到形如 http://services.unimarketing.com.cn/auth/callback?oauth_token=ab3cd9j4ks73hf7g的url, 其中oauth_token为授权Request Token 否则需要用户手工通知第三方应用以完成授权
  • 第三步:使用授权后的 Request Token 换取 Access Token(请求URL:http://services.unimarketing.com.cn/auth/access_token)
    • 请求参数 意 义
      oauth_consumer_key OAuth Consumer Key
      oauth_token 第一步中获得的Request Token
      oauth_signature_method 签名方法
      oauth_signature 签名值
      oauth_timestamp 时间戳
      oauth_nonce 单次值, 防止重复提交
  • 第四步:使用Access Token访问或修改受保护资源(请求URL为具体的某个API)
    • 请求参数 意 义
      oauth_consumer_key OAuth Consumer Key
      oauth_token Access Token
      oauth_signature_method 签名方法
      oauth_signature oauth_token 的签名值
      oauth_timestamp 时间戳
      oauth_nonce 单次值, 防止重复提交

关于在修改删除受限资源时传递OAuth参数
  • OAuth规范定义了三种传递OAuth参数方式
    a、header中
    b、url中
    c、post form中
    然而进行POST、PUT、DELETE请求时,灵动创新暂时不支持使用在url中或者post form中传递OAuth参数。
    因此你只能选择在header中传递OAuth参数。格式如下:
    Authorization: OAuth realm="http://www.example.com/",
    oauth_consumer_key="api.third.com",
    oauth_token="ad180jjd733klru7",
    oauth_signature_method="HMAC-SHA1",
    oauth_signature="wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D",
    oauth_timestamp="137131200",
    oauth_nonce="4572616e48616d6d65724c61686176",
    oauth_version="1.0"
平台介绍
关于我们 | 联系我们 | 行业应用 | 专业术语 | 资源中心 | 隐私声明
© 2022 灵动创新(北京)科技有限公司 - 京ICP备16028763号-1