Web API with individual account and local login in ASP.NET Web API 2.2

Web API with individual account and local login in ASP.NET Web API 2.2

這一篇文章是使用 OAtuh2

OAuth2 的專有名詞:

  • Resource : 想要藏起來的 data
  • Resource server : 把 Resource 存起來的地方
  • Resource owner : 允許誰能夠進來拿到 Resource
  • Client : 想要 Resource 的人, (web browser)
  • Access Token : 許可證, 表示證明你可以進入拿到 Resource
  • Bearer Token : 許可證的一種, 任何人只要拿到這一個許可證就可以進去拿 Resource, 看卡不看人, 有卡就可以
  • Authorization server : 發放 Access Token 的 server

Local Login Credential Flow

  1. 使用者登入帳密
    2.Client, 這裡的 Client 是 Web Browser, 把使用者的帳密拿去給 Authorization Server 做比對
    3.Authorization Server 做比對完之後, 會發放一個 Access Token 給 Client

4.Client 再把這一個 Access Token 塞到 Http Request 的 header 來拿到這一個機密的 Resource


Individual Accounts

如果選擇 Individual Accounts 在 Web API 的 Authentication, 專案會有一個比對 User Credentials 和 Access Token 的Authentication Server, 在這一個時候, Web API Controller所扮演的腳色就是上述所說的 Resource server (把資料存起來的地方),
Authentication Filter 會比對 Access Token, 以及被 [Authorize] 所保護的 classes 或者是 actions, 當 Controller 的 class 有 [Authorize] 這一個 Attribute, 每一個 request 都要被認證之後才能拿到 Resource, 要不然會回傳 401 Error (Unauthorized)

https://docs.microsoft.com/en-us/aspnet/web-api/overview/security/individual-accounts-in-web-api#local-login-credential-flow

留言

這個網誌中的熱門文章

ASP.NET Web API - DTOs

Scaffold Identity into the Current Project

Passing data from controller to the view