首先修改config.cs 新增client
new client
,postlogoutredirecturis = ,
clientsecrets = ,
alwaysincludeuserclaimsinidtoken=true,
//alwayssendclientclaims = true,
allowofflineaccess=true,
allowedscopes = ,
//允許將token通過瀏覽器傳遞
allowaccesstokensviabrowser = true,
requireconsent = false
}
新增mvc客戶端codeclient
啟動埠設定為7001
安裝nuget包
dotnet add pacakage identityserver4
註冊服務
在startup.cs中configureservices方法新增如下**:
services.addauthentication(options =>
).addcookie(cookieauthenticationdefaults.authenticationscheme) //使用cookie作為驗證使用者的首選方式
.addopenidconnect(openidconnectdefaults.authenticationscheme, options =>
);
配置管道
修改startup.cs中configure方法:
else
//");
});}
homecontroller的privacy新增授權[authorize]
修改privacy.cshtml
@using microsoft.aspnetcore.authentication@foreach (var claim in user.claims)
@foreach (var prop in (await context.authenticateasync()).properties.items)
修改_layout.cshtml新增以下**
@if (user.identity.isauthenticated)
修改homecontroller.cs
public iactionresult logout()
/// /// 測試請求api資源(api1)
}
啟動並且登入並點選【掉用api】
大功告成
Identity Server4學習筆記
學習參考資料 博文 學習前的預備知識 oauth 2.0 的乙個簡單解釋 和 oauth 2.0 的四種方式 這個博主的文非常適合做課後總結 因為以上的博文其實已經很詳細了,我也就記一下學習過程中老是誤解的部分。oauth 2.0是乙個委託協議,它可以讓那些控制資源的人允許某個應用以代表他們來訪問他...
授權認證(IdentityServer4
區別 openid authentication 認證 oauth aurhorize 授權 輸入賬號密碼,qq確認輸入了正確的賬號密碼可以登入 認證 下面需要勾選的核取方塊 獲取暱稱 頭像 性別 授權 openid 當你需要訪問a 的時候,a 要求你輸入你的openid,即可跳轉到你的openid...
Identity Server4學習系列一
一 前言 這是官方文件的位址 二 簡介 1 常見的 的互動方式如下 1 瀏覽器與web應用程式互動。單站點應用程式,乙個站點搞定所有的東西,常見的有mvc webform等等,這類一般不存在多客戶端之說,因為頁面和後台處理程式是強耦合的,也就是說,這個時候我們的後台處理程式只處理對應的頁面,不能給其...