文章出處

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"
    }
}

文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()