寫在前邊
客戶端:你的網(wǎng)站
認證服務器/服務端:微信
1、授權碼模式:authorization code(微信網(wǎng)頁登錄)
1)用戶訪問客戶端填物,客戶端(網(wǎng)站)將用戶導向認證服務器
2)用戶選擇是否給客戶端授權
response_type=code
scope
https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect
3)假設用戶給予授權冰单,認證服務器將用戶302到客戶端(網(wǎng)站)指定的URI上幌缝,并同時給出一個授權碼 code
redirect_url?code=xx
4)客戶端(網(wǎng)站)收到授權碼,向認證服務器發(fā)送code和URI(URL目前沒有見過)诫欠,認證服務器核對code后涵卵,返回access_token 和 refresh_token
grant_type=authorization_code 授權碼模式
https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
2、客戶端模式(企業(yè)和企業(yè)的B2B交互模式與C端用戶無關荒叼,基本都是分銷對接之類在使用)
1)客戶端(網(wǎng)站)向認證服務器通過client_id和secert獲取Header的Authorization basic
grant_type=client_credentials
https://www.authorize.com/Authorize/token
POST
client_id:xxx
secret:xxx
grant_type:client_credentials
2)認證服務器返回一個token轿偎,在請求其它服務端API時在Header帶上,有scope限制
看業(yè)務
Authorization:bear xxxxxxtokenxxxxxxx
或
Authorization:basic xxxxxxtokenxxxxxxx
3被廓、密碼模式(簡單)
1)用戶訪問客戶端(網(wǎng)站)時需要輸入用戶名和密碼坏晦,客戶端(網(wǎng)站)再向認證服務器去獲取access_token
https://www.authorize.com?response_type=password&username=xxx&password=xxx
認證服務器返回access_token
千萬不要對第三方企業(yè)提供賬號密碼,只能用在自家的服務器中使用嫁乘,防止泄密 @バ觥!蜓斧!
4仓蛆、簡化模式 Implicit Grant Type (非安全模式)不推薦且沒用過
1)用戶訪問客戶端(網(wǎng)站),客戶端(網(wǎng)站)將用戶導向認證服務器
2)用戶選擇是否給客戶端(網(wǎng)站)授權
response_type=token
http://www.authorize.com?response_type=token&client_id=xxx&state=xxx&redirect_url=xxx
3)用戶授權后認證服務器將用戶導向 redirect_url中且包含了access_token
redirect_url?access_token=xxx