AspNetCore3.1_Secutiry原始碼解析_2_Authentication_核心物件
阿新 • • 發佈:2020-03-19
---
title: "AspNetCore3.1_Secutiry原始碼解析_2_Authentication_核心流程"
date: 2020-03-18T21:19:15+08:00
draft: false
---
# 系列文章目錄
- [AspNetCore3.1_Secutiry原始碼解析_1_目錄](https://holdengong.com/aspnetcore3.1_secutiry原始碼解析_1_目錄)
- [AspNetCore3.1_Secutiry原始碼解析_2_Authentication_核心專案](https://holdengong.com/aspnetcore3.1_secutiry原始碼解析_2_authentication_核心流程)
- AspNetCore3.1_Secutiry原始碼解析_3_Authentication_Cookies
- AspNetCore3.1_Secutiry原始碼解析_4_Authentication_JwtBear
- AspNetCore3.1_Secutiry原始碼解析_5_Authentication_OAuth
- AspNetCore3.1_Secutiry原始碼解析_6_Authentication_OpenIdConnect
- AspNetCore3.1_Secutiry原始碼解析_7_Authentication_其他
- AspNetCore3.1_Secutiry原始碼解析_8_Authorization_核心專案
- AspNetCore3.1_Secutiry原始碼解析_9_Authorization_Policy
# 依賴注入
框架提供了三個依賴注入過載方法。
```csharp
//注入認證服務
services.AddAuthentication();
//注入認證服務並制定預設架構名
services.AddAuthentication("Cookies");
//注入認證服務並設定配置項
services.AddAuthentication(config =>
{
});
```
看看注入程式碼
```csharp
public static AuthenticationBuilder AddAuthentication(this IServiceCollection services)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
services.AddAuthenticationCore();
services.AddDataProtection();
services.AddWebEncoders();
services.TryAddS