園子中關於IDSV的文章有很多,但是作為一個小白的我,始終不能跟隨眾大佬的步伐,遂寫下這篇IDS的這篇最佳實踐。
閱讀本文前,你需要了解以下知識:
1) 了解什么是OAuth2?
參考文獻:
http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html
2) 什么是OIDC?
3)什么是IDS4?
https://identityserver4.readthedocs.io/en/release/
以及曉晨master的中文參考文檔 https://www.cnblogs.com/stulzq/p/8119928.html
雨夜朦朧的源碼分析文檔 http://www.cnblogs.com/RainingNight/p/introduce-basic-authentication-in-asp-net-core.html
BlackHeart的OIDC實戰SSO http://www.cnblogs.com/linianhui/p/oidc-in-action-sso.html#auto_id_1
本文依賴的環境如下:
1)netcore2.1環境下的IDSV服務器
2)netcore2.1/netfx環境下對應的客戶端接入服務器
3)netcore2.1/netfx環境下對應的驗證服務器為1)
一)服務器接入MYSQL腳本設置以及對應表字段含義注解【非官方】
新建一個空白的.netcore應用網站,Nuget拉取以下dll包,IdentityServer4;IdentityServer4.EntityFramework;Microsoft.AspNetCore.All;
參考官方示例 https://github.com/IdentityServer/IdentityServer4.Samples,將其中的Quickstart5_HybridAndApi對應服務端代碼拷貝到自己的server中,解決方案截圖如下

接下來,我們要做的第一步就是關於示例中api資源,標識資源以及token相關信息存儲的數據庫建表入庫。
我這是使用EF的導入功能完成的。主要步驟包含以下:
1)首先添加如下這句話到對應的項目工程文件中
-
- 注入DI鏈接
- 修改關於IClientStore, IResourceStore, and ICorsPolicyService,IPersistedGrantStore的實現為EF implementation。
dotnet ef migrations add InitialIdentityServerPersistedGrantDbMigration -c PersistedGrantDbContext -o Data/Migrations/IdentityServer/PersistedGrantDb dotnet ef migrations add InitialIdentityServerConfigurationDbMigration -c ConfigurationDbContext -o Data/Migrations/IdentityServer/ConfigurationDb
此時將在解決方案中生成兩個文件夾。
5)執行code first常規操作,將dll中數據庫遷移到localdb,本文是使用mssql,其余的也是類似。
-
- 建立一個服務service文件,負責遷移數據。
- 在全局服務中注冊執行即可。
