文章出處
文章列表
IdentityServer4 在登錄完成的適合,會再跳轉一次頁面(權限確認),如下:
我之前以為 IdentityServer4 就是這樣使用的,但實際業務場景并不需要進行權限確認,而是登陸成功后直接跳轉到之前的頁面就行了,所以,為了實現這個需求,我做了很多兼容操作,比如 IdentityServer4 授權中心有個 ConsentController,登錄完成之后直接跳轉到這個 Controller,頁面不需要呈現,而是直接完成,當然代碼寫的很簡陋,我總怕后面會出現一些問題。
今天又搜了下相關關鍵詞(之前搜了無數遍,也沒找到解決方案),無意間看到一個 Issue:Consent screen - can it be dropped?,解決方式非常簡單,只需要配置RequireConsent = false
,示例代碼:
new Client
{
ClientId = "client1",
ClientName = "tets",
AllowedGrantTypes = GrantTypes.Implicit,
AllowAccessTokensViaBrowser = true,
AccessTokenLifetime = 10,//最小值是5分鐘 https://github.com/IdentityServer/IdentityServer4.Samples/issues/14
RedirectUris = { "http://localhost:5003/callback.html" },
//PostLogoutRedirectUris = { "http://localhost:5003/index.html" },
AllowedCorsOrigins = { "http://localhost:5003" },
RequireConsent = false, //禁用 consent 頁面確認
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"api1"
}
}
文章列表
全站熱搜