现在的位置: 首页 > 综合 > 正文

OAuth授权机制

2018年04月18日 ⁄ 综合 ⁄ 共 2858字 ⁄ 字号 评论关闭

关于OAuth

OAuth协议旨在为用户资源提供一个安全开放的标准。目前支持OAuth 1.0a。

三歩走

1.requestToken

接口说明:获取未授权的临时 token

接口协议:HTTPS GET

URL 结构:https://openapi.kuaipan.cn/open/requestToken

接口参数:

Name Required Type and Limit Description
oauth_consumer_key Y string 第1步的 consumer_key
oauth_signature_method N string 请用 "HMAC-SHA1"
oauth_signature Y string 本次请求的签名,生成方法请参考附录-签名生成算法
oauth_timestamp Y int 时间戳,正整数,和标准时间不超过5分钟
oauth_nonce Y string [ 0-9A-Za-z_ ]随机字符串,长度小于32字节。每次请求请使用不同的nonce
oauth_version N string 请填 "1.0"
oauth_callback N string 回调函数

请求示例(换行和缩进只是为了更好的展示):

https://openapi.kuaipan.cn/open/requestToken?
        oauth_nonce=33233984&
        oauth_timestamp=1331181769&
        oauth_consumer_key=662d78dbbc7944a4ba7a5d491b158a0c&
        oauth_signature_method=HMAC-SHA1&
        oauth_version=1.0&
        oauth_signature=4zGJGW3NpedYuUHULGnp8Bae98k%3D

返回HTTP的状态码含义,请参考附录-HTTP状态码

若HTTP状态码为200,消息体返回参数(当前只支持返回JSON化字符串):

Name Required Type and Limit Description
oauth_token Y string 未授权的token
oauth_token_secret Y string 对应secret
oauth_callback_confirmed Y JSON boolean True/False,callback是否接收

JSON示例:

{
        "oauth_token_secret": "b3697c3165ad473a864ae4d295003d0d",
        "oauth_token": "8519c219d45545ce8d4fb423140c9061", 
        "oauth_callback_confirmed": False
}

2.authorize

接口说明:用户验证 token。这个接口返回是一个 web 页面,要求快盘用户登陆和授权。

接口协议:HTTPS GET

URL 结构:

https://www.kuaipan.cn/api.php?ac=open&op=authorise&oauth_token=<YourTemporaryToken>

接口描述:此页面中会要求用户登陆,然后选择同意或者拒绝对应用授权。授权成功后:

A:web应用会重定向到 oauth_callback 所指定的URL(含返回参数)。

B:客户端应用(oauth_callback不传)会在网页中给出授权码,用户需要手工将验证码输入到应用中才能完成授权流程。

授权地址(引导用户授权):

https://www.kuaipan.cn/api.php?ac=open&op=authorise&oauth_token=8519c219d45545ce8d4fb423140c9061

返回参数:

如果指定 callback,则会把下面2个值post到指定的 callback,否则可以跳到第三步。

Name Required Type and Limit Description
oauth_token Y string 用户授权的 token
oauth_verifier Y string 验证码,用于 accessToken

3.accessToken

接口说明:用临时 token 换取 access token。

接口协议:HTTPS GET

URL结构:https://openapi.kuaipan.cn/open/accessToken

接口参数:

Name Required Type and Limit Description
oauth_consumer_key Y string 第1步的 consumer_key
oauth_signature_method N string 请用 "HMAC-SHA1"
oauth_signature Y string 本次请求的签名,生成方法参考RFC58493.4 HMAC-SHA1签名部分,或参考附录-签名生成算法
oauth_timestamp Y int 时间戳,正整数,和标准时间不超过5分钟
oauth_nonce Y string [ 0-9A-Za-z_ ]随机字符串,长度小于32字节
oauth_version N string 请填 "1.0"
oauth_token Y string 临时 token
oauth_verifier N string 上一步返回的验证码,为了简化用户操作,可以不填verifier,但是前提是必须有用户通过了授权

请求示例:(换行和缩进只是为了更好的展示)

https://openapi.kuaipan.cn/open/accessToken?
        oauth_nonce=95000720&
        oauth_timestamp=1331181774&
        oauth_consumer_key=662d78dbbc7944a4ba7a5d491b158a0c&
        oauth_signature_method=HMAC-SHA1&
        oauth_version=1.0&
        oauth_token=4e5cac43baf441cc88fba684855e248d&
        oauth_signature=0wziZZcdm4IrR2v5WlksFbEiAgI%3D

接口返回:

返回HTTP的状态码含义,请参考附录-HTTP状态码

若HTTP状态码为200,消息体返回参数(当前只支持返回JSON化字符串):

Name Required Type and Limit Description
oauth_token Y string 已经授权的 token
oauth_token_secret Y string 对应 secret
charged_dir N string 可见的根目录 ID
user_id Y string 用户id

JSON示例:

{
        "oauth_token_secret": "e76ccab72f9f44f1a445d15b798c4fd2", 
        "oauth_token": "fe6265afa5c74866a62573b34ca411fb", 
        "user_id": 101, 
        "charged_dir": "0"
}

抱歉!评论已关闭.