<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ## 第一步:引導用戶到認證服務器(授權登錄) 在登錄界面,引導用戶選擇商城第三方授權登錄,用戶點擊后跳轉到商城授權頁面。授權頁面地址獲取方法如下: #### url地址 >**{host}/oauth2/authorize?response_type=code&client_id=YOUR_API_ID&redirect_uri=REDIRECT_URL&state=NONCESTR** #### url參數 * `response_type`:表示響應類型,必選項,此處的值固定為code * `client_id`:表示客戶端的ID,即簽約成功后獲得的API Key,用來標志授權請求的來源,必選項 * `redirect_uri`:授權后重定向的回調鏈接地址,請使用urlencode對鏈接進行處理 * `state`:表示客戶端的當前狀態,認證服務器會原封不動地返回這個值 ,用于保持請求和回調的狀態,授權請求后原樣帶回給第三方。該參數可用于防止csrf攻擊(跨站請求偽造攻擊),建議第三方帶上該參數,可設置為簡單的隨機數加session進行校驗。 #### 例子 [https://api_test.employeechoice.cn/v1/oauth2/authorize?response_type=code&client_id=100001&redirect_uri=https%3a%2f%2fwww.baidu.com%2f&state=bb38108d1aaf567c72da0f1167e87142d0e20cb2bb24ec5a](https://api_test.employeechoice.cn/v1/oauth2/authorize?response_type=code&client_id=100001&redirect_uri=https%3a%2f%2fwww.baidu.com%2f&state=bb38108d1aaf567c72da0f1167e87142d0e20cb2bb24ec5a) <br> ## 第二步:用戶同意為第三方應用授權(獲取Authorization Code) 這一步,對于用戶來說,同意授權即可。對于開發者來說,就是獲取code。用戶授權并登錄后,授權服務器首先會post一個請求回服務器進行用戶認證,認證通過后授權服務器會生成一個授權碼,然后認證服務器會回調redirect_uri,并返回授權碼code和授權請求中傳遞的state #### 回調實例 [http://www.baidu.com?code=093B9307E38DC5A2C3AD147B150F2AB3&state=bb38108d1aaf567c72da0f1167e87142d0e20cb2bb24ec5a](http://www.baidu.com?code=093B9307E38DC5A2C3AD147B150F2AB3&state=bb38108d1aaf567c72da0f1167e87142d0e20cb2bb24ec5a) 注意:`093B9307E38DC5A2C3AD147B150F2AB3` 就是返回的授權碼。請務必快速執行此操作,因為授權代碼會在30秒后到期,且只能使用一次! <br> <br> ## 第三步: 使用授權碼向認證服務器申請令牌(獲取access_token) 開發者拿到認證服務器返回的授權碼(Authorization Code)后,需要根據授權碼再次向認證服務器申請令牌(access_token) ~~~[api] post:https://api_test.employeechoice.cn/v1/oauth2/accessToken *string:client_id=#表示客戶端的ID,即簽約成功后獲得的API Key,用來標志授權請求的來源 *string:client_secret#認證密鑰,簽約成功后獲取的API Secret,機密信息十分重要 *string:redirect_uri#授權時傳的回調地址,必須和第一步保持一致,主要驗證來源 *string:grant_type=authorization_code#授權類型,此處的值固定為authorization_code *string:code#授權碼 <<< success { "access_token": "fe7c425d163ba7739a710b1fe0f63184bc8cf703", "expires_in": 3600, "token_type": "Bearer", "scope": null, "refresh_token": "c4ead4fb10f663d7df0087a36b892b9576fd3daf"// 刷新用的token } <<< error { "error": "invalid_grant", // 錯誤代碼 "error_description": "Authorization code doesn't exist or is invalid for the client" // 錯誤信息 } ~~~ <br> <br> ## 第四步:向資源服務器申請資源(獲取開放數據) 到這一步OAuth2.0的流程可以說是結束了,但是對于開發者來說還有重要的事情要做。那就是: **拿到token、openid和用戶信息這么重要數據保到自己數據庫,實現自己的業務邏輯** 有了token,再向資源服務器提供的資源接口發送請求,資源服務器校驗令牌無誤后,就會返回開放接口數據。 #### 1. 獲取平臺openid ~~~[api] get:https://api_test.employeechoice.cn/v1/oauth2/getOpenId?access_token=fe7c425d163ba7739a710b1fe0f63184bc8cf703 *string:access_token#令牌 <<< success { "status": 1, "msg": "操作成功!", "result": { "access_token": "eef4b2de110b205a85ba7ef3d941f2eeef0aea58", "client_id": "100001", "expires": 1536083506, "scope": null, "open_id": "619ebba6722756fdcb2654068df5ee4c" } } <<< error { "error": "invalid_token", "error_description": "The access token provided is invalid" } ~~~ #### 2. 獲取用戶信息 ~~~[api] get:https://api_test.employeechoice.cn/v1/oauth2/getUserInfo?access_token=fe7c425d163ba7739a710b1fe0f63184bc8cf703 *string:access_token#令牌 <<< success { "status": 1, "msg": "操作成功!", "result": { "seller_name": "倍升互聯(北京)科技有限公司", } } <<< error { "error": "invalid_token", "error_description": "The access token provided is invalid" } ~~~ <br> ## 第五步:令牌延期(刷新) 為了安全性考慮,返回的`access_token`是有時間限制的,上面返回的令牌有效期為10小時,access_token失效時,需要重新向認證平臺申請授權。 #### 用例 * 允許客戶長時間訪問用戶的資源 * 檢索具有相同或較小范圍的其他標記以進行單獨的資源調用 ~~~[api] post:https://api_test.employeechoice.cn/v1/oauth2/refreshToken *string:client_id#表示客戶端的ID,即簽約成功后獲得的API Key,用來標志授權請求的來源 *string:client_secret#認證密鑰,簽約成功后獲取的API Secret,機密信息十分重要 *string:grant_type=refresh_token#授權類型,refresh_token *string:refresh_token#刷新令牌 <<< success { "access_token": "fe7c425d163ba7739a710b1fe0f63184bc8cf703", "expires_in": 3600, "token_type": "Bearer", "scope": null, "refresh_token": "c4ead4fb10f663d7df0087a36b892b9576fd3daf"// 刷新用的token } <<< error { "error": "invalid_grant", // 錯誤代碼 "error_description": "Authorization code doesn't exist or is invalid for the client" // 錯誤信息 } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看