卖逼视频免费看片|狼人就干网中文字慕|成人av影院导航|人妻少妇精品无码专区二区妖婧|亚洲丝袜视频玖玖|一区二区免费中文|日本高清无码一区|国产91无码小说|国产黄片子视频91sese日韩|免费高清无码成人网站入口

CORE Identity簡(jiǎn)化模式服務(wù)端配置幫助類

Core Identity簡(jiǎn)化(隱形)模式服務(wù)端在配置時(shí),可以通過(guò)新增Identity配置幫助類來(lái)更加方便地管理相關(guān)對(duì)象和資源。以下是針對(duì)服務(wù)端的配置幫助類的具體實(shí)現(xiàn)。 新增Identity配置幫助

Core Identity簡(jiǎn)化(隱形)模式服務(wù)端在配置時(shí),可以通過(guò)新增Identity配置幫助類來(lái)更加方便地管理相關(guān)對(duì)象和資源。以下是針對(duì)服務(wù)端的配置幫助類的具體實(shí)現(xiàn)。

新增Identity配置幫助類

在服務(wù)端中,我們可以新增一個(gè)名為IdentityConfig的配置幫助類,用于管理可訪問(wèn)的對(duì)象、客戶端配置以及用戶配置等信息。這樣可以更好地組織和管理相關(guān)資源,提高代碼的可讀性和維護(hù)性。

```csharp

using System;

using ;

using ;

using ;

using ;

using ;

using ;

using IdentityServer4.Test;

namespace IdentityServerPeizhi

{

public class IdentityConfig

{

// 可訪問(wèn)的對(duì)象

public static IEnumerable GetResource()

{

return new List

{

new ApiResource("apiServer", "apiServer")

};

}

// 客戶端配置

public static IEnumerable GetClients()

{

return new List

{

new Client

{

ClientId"clientId",

AllowedGrantTypes ,

ClientSecrets { new Secret("secret1122".Sha512()) },

AllowedScopes{ "apiServer" }

}

};

}

// 添加用戶配置

public static List GetTestUsers()

{

return new List

{

new TestUser

{

SubjectId "111",

Username "test111",

Password "123456"

}

};

}

// 身份資源配置

public static IEnumerable GetIndentityReources()

{

return new List

{

new (),

new (),

new ()

};

}

}

}

```

Startup.cs配置服務(wù)

在Startup.cs文件中,通過(guò)ConfigureServices方法配置Identity Server服務(wù),包括添加IdentityServer、數(shù)據(jù)庫(kù)上下文、用戶存儲(chǔ)等內(nèi)容,以確保服務(wù)正常運(yùn)行。

```csharp

public void ConfigureServices(IServiceCollection services)

{

()

.AddDeveloperSigningCredential()

.AddInMemoryClients(())

.AddInMemoryApiResources(())

.AddInMemoryIdentityResources(())

.AddTestUsers(());

(options >

(("DefaultConnection")));

()

.AddEntityFrameworkStores()

.AddDefaultTokenProviders();

();

();

}

```

配置Startup.cs中的Configure方法

在Startup.cs文件的Configure方法中,配置應(yīng)用程序的中間件,包括開發(fā)環(huán)境判斷、異常處理、靜態(tài)文件服務(wù)、Identity Server等內(nèi)容,并設(shè)置路由規(guī)則以確保應(yīng)用程序正常運(yùn)行。

```csharp

public void Configure(IApplicationBuilder app, IHostingEnvironment env)

{

if (())

{

();

();

();

}

else

{

("/Home/Error");

}

();

();

(routes >

{

(

name: "default",

template: "{controllerHome}/{actionIndex}/{id?}");

});

}

```

登錄設(shè)置,過(guò)期時(shí)間等

在具體的登錄控制器中,可以配置登錄的驗(yàn)證邏輯,包括用戶名密碼驗(yàn)證、用戶信息獲取等操作,并設(shè)置過(guò)期時(shí)間等相關(guān)屬性,以確保用戶登錄的安全性和有效性。

```csharp

public async Task Login(LoginViewModel model, string returnUrl null)

{

if (_("test111", "123456"))

{

var user _("test111");

var props new AuthenticationProperties

{

IsPersistent true,

ExpiresUtc ((30))

};

await (HttpContext, , , props);

}

return View(model);

}

```

通過(guò)以上的配置和實(shí)現(xiàn),我們可以更好地管理Identity Server的相關(guān)資源和客戶端配置,確保服務(wù)端的安全性和穩(wěn)定性。同時(shí),在登錄設(shè)置中,可以控制登錄的有效期和安全性,提升用戶體驗(yàn)和系統(tǒng)安全性。

標(biāo)簽: