前言
在一些比較舊或是獨立的系統,常常會使用到 Resource Owner Password Credentials (ROPC) 的方式來取得 access token。
就是使用者在 Client Application 功能輸入帳/密後,再由 Client Application 將使用者的帳/密 Post 到 Authorization Server 來取回 access token。
這樣帳/密不就被 Client Application 取得了嗎!!!
OAuth 2.0 - Resource Owner Password Credentials (ROPC)
以下以 IdentityServer4 的方式來說明
1.在 IdentityServer4 中註冊使用 ROPC 的 Client
1 | new Client |
2.Post 帳/密資訊給 IdentityServer 的 token ,grant_type 為 password ,取回 access token,並放在 localStorage 之中
1 | var ropcUrl = `https://localhost:5001/connect/token`; |

很簡潔的方式,但使用者的帳/密卻被 Client Application 知道,
建議改用 OAuth 2.0 - Proof Key for Code Exchange (PKCE)