-
-
Save kevchentw/8a973139db8b14513c99 to your computer and use it in GitHub Desktop.
交通大學 OAuth 服務 - 說明文件
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 交通大學 OAuth 服務 - 說明文件 | |
| ==================== | |
| 本文件將簡單介紹如何透過交通大學OAuth服務獲取使用者帳號名稱。本平台是依據OAuth 2.0 (RFC6749)的標準開發,目前僅開放 `Authorization Code` 方式來認證。 | |
| 平台網址:http://id.nctu.edu.tw/ | |
| 測試開發者帳號: | |
| - 帳號名稱: `[email protected]` | |
| - 密碼: `test` | |
| 測試使用者帳號: | |
| - 帳號名稱: `[email protected]` | |
| - 密碼: `test` | |
| ---------- | |
| 認證方法 | |
| ========= | |
| (一)申請應用程式 | |
| -- | |
| 1. 連接到平台網頁 `http://id.nctu.edu.tw/` | |
| 2. 透過測試開發者帳號登入 | |
| 3. 在此頁面 `http://id.nctu.edu.tw/apply/new/` 申請一個新的應用程式 | |
| * Client type: public | |
| * Authorization grant type: authorization-code | |
| * Redirect uris: 請填寫欲串接平台對應接收OAuth參數之網址,此以 `http://example.com/oauth/` 作為範例 | |
| 4. 在此頁面找到 `http://id.nctu.edu.tw/apply/`,獲取剛剛所申請到的 Client Id, Client Secret, Redirect uris | |
| 5. 將帳號登出 | |
| (二)獲取使用者授權 | |
| -- | |
| 1. 透過瀏覽器開啟 | |
| `http://id.nctu.edu.tw/o/authorize/?client_id=<Client id>&scope=get_username&response_type=code` | |
| 2. 透過測試使用者帳號登入,然後按下授權 | |
| 3. 成功授權後,瀏覽器會導向 `http://example.com/oauth/?code=<Code>` | |
| 4. 請保留此 `<Code>` 參數與伺服器換取Token | |
| 三: 與OAuth伺服器換取Token | |
| -- | |
| 1. 透過 POST 方式 `http://id.nctu.edu.tw/o/token/`,form-data 包含以下資料 | |
| `` grant_type: authorization_code | |
| code: <Code> | |
| client_id:<Client id> | |
| client_secret: <Client Secret> | |
| redirect_uri: <URL> `` | |
| 2. 伺服器應回傳以下資料 | |
| ``{ | |
| "token_type": "Bearer", | |
| "expires_in": 36000, | |
| "access_token": <Access Token>, | |
| "scope": "get_username", | |
| "refresh_token": <Refresh Token> | |
| }`` | |
| 四: 獲取使用者帳號名稱 | |
| -- | |
| 1. 透過 GET 方式 `https://id.nctu.edu.tw/o/username/` | |
| 並在header中附上 `Authorization: Bearer <Access Token>` | |
| 2. 伺服器回傳使用者名稱 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment