Skip to content

Instantly share code, notes, and snippets.

@libo1106
Created February 24, 2014 16:50
Show Gist options
  • Save libo1106/9192057 to your computer and use it in GitHub Desktop.
Save libo1106/9192057 to your computer and use it in GitHub Desktop.
安全的HTTP鉴权方式
# 安全的鉴权方式
_对appKey用时间戳进行加盐处理_
```
我们服务端目前支持一种新的 API 鉴权方式,用户仍然需要传递X-AVOSCloud-Application-Id的 http 头表示 App id,但是不需要再传递X-AVOSCloud-Application-Key。
替代地,增加了新 HTTP 头部——X-AVOSCloud-Request-Sign头,它的值要求是一个形如sign,timestamp[,master]的字符串,其中:
timestamp(必须) - 客户端产生本次请求的 unix 时间戳,精确到毫秒。
sign(必须)- 将 timestamp 加上 app key(或者 master key) 组成的字符串做 MD5 签名。
master (可选)- 字符串 "master",当使用 master key 签名请求的时候,必须加上这个后缀明确说明是使用 master key。
我们举个例子来说明:假设
应用 App id 为mdx1l0uh1p08tdpsk8ffn4uxjh2bbhl86rebrk3muph08qx7,
App key 为n35a5fdhawz56y24pjn3u9d5zp9r1nhpebrxyyu359cq0ddo,
Master key 为h2ln3ffyfzysxmkl4p3ja7ih0y6sq5knsa2j0qnm1blk2rn2。
那么:
x-avoscloud-request-sign: 28ad0513f8788d58bb0f7caa0af23400,1389085779854 -- 表示请求时间戳为1389085779854,签名为28ad0513f8788d58bb0f7caa0af23400,签名是通过对1389085779854n35a5fdhawz56y24pjn3u9d5zp9r1nhpebrxyyu359cq0ddo的字符串做 md5sum 得到,也就是时间戳加上 app key 组成的字符串做 MD5 签名。
x-avoscloud-request-sign: c884fe684c17c972eb4e33bc8b29cb5b,1389085779854,master -- 表示使用 master key 产生签名,时间戳仍然是1389085779854,签名是通过对1389085779854h2ln3ffyfzysxmkl4p3ja7ih0y6sq5knsa2j0qnm1blk2rn2做 md5sum 得到,最后的 master 告诉服务器这个签名是使用 master key 产生的。
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment