1. 基本概念
1.1. 词汇表
HTTP客户端, 具有发送OAuth-authenticated请求能力的HTTP客户端
HTTP服务器, 具有接收OAuth-authenticated请求能力的HTTP服务器.
受保护的资源, 在获得了OAuth认证后能访问的资源.
资源所有者, 具有访问和控制资源的所有者, 并能够通过OAuth认证后将访问权利授权给某客户端.
- client credentials: consumer key and secret.
- temporary credentials: request token and secret.
- Token credentialss: Access Token and secret
-
request token
-
access token
客户端程序, 需要进行OAuth认证的客户端程序, 通常包含一对key/secret, 相当于普通登录的username, password. 在客户端(client)用key, secrect向提供OAuth认证API(OAuth-enabled API)的服务器(OAuth Server)进行认证.
服务器程序, 提供OAuth认证.
资源所有者.
1.2. 基本流程
-
server提供给client一对 key 和 secret.
-
客户端利用 key 和 secret 及其他参数向服务器请求得到一个 request token ,例如请求网址: http://server/oauth/request_token .
-
要求用户对 request token 进行授权.例如网址: http://server/oauth/authorize . 一般性操作为:.
-
server提供认证页面进行用户认证, 类似于普通登录页面, 以确定用户身份, 身份认证成功后转入询问用户是否确定授权页面, 例如: http://server/oauth/confirm
-
server询问用户是否授权该 request token , 即允许该client访问受保护资源.
-
用户确定允许访问, 则该 request token 被server标记为已授权, 然后将用户重定向到client之前提供的 oauth_callback 页面, 并将 oauth_token 值传回客户端以表示该 request token 已被用户授权. ( oauth_token 等于 request token .
-
-
client此时可利用已被用户授权的 request token 向server交换得到一个 access token , 拥有该 access token , client则可以访问受保护资源, 并且在该 access token 过期以前反复使用它. 例如请求网址: http://server/oauth/access_token
1.3. 页面及其参数
1.3.1. /request_token
参数 | 意义 |
oauth_consumer_key | API key |
oauth_onoce | 单次值, 随机字符串 |
oauth_signature | 签名值, 利用某种算法对 secret 生成的签名. |
oauth_signature_method | 签名方法 |
oauth_timestamp | 时间戳 |
oauth_version | 可选, 但必须为 1.0 |
无
1.3.2. /authorize
参数 | 意义 |
oauth_token | 之前的 Request Token |
oauth_callback | 认证后重定向回客户端的url. |
参数 | 意义 |
oauth_token | 已被授权的Request Token |
1.3.3. /access_token
参数 | 意义 |
oauth_consumer_key | API Key . |
oauth_token | 已被授权的 request token. |
oauth_signature | 签名值. |
oauth_signature_method | 签名方法. |
oauth_timesramp | 时间戳. |
oauth_nonce | 单次值. |
参数 | 意义 |
oauth_token | 已被授权的 access token |