久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

更新 ClaimsPrincipal 中的聲明

Update claims in ClaimsPrincipal(更新 ClaimsPrincipal 中的聲明)
本文介紹了更新 ClaimsPrincipal 中的聲明的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我將 Adal 與 Azure Active Directory 一起使用,我需要通過自定義 OwinMiddleware 添加額外的聲明.當我向該主體添加聲明時,我可以在當前請求中訪問它們.但刷新頁面后,聲明消失了.

I am using Adal with Azure Active Directory and I need to add extra claims via custom OwinMiddleware. When I add claims to this principal, I am able to access them in the current request. But after a page refresh, the claim is gone.

我以為 Owin 處理了聲明的序列化并將其放入 cookie 本身,但事實并非如此.

I thought Owin handled serialization of claims and put it into a cookie itself, but this doesn't seem to be the case.

我添加聲明如下:

 var claimsIdentity = (ClaimsIdentity) ClaimsPrincipal.Current.Identity;
        if (!claimsIdentity.IsAuthenticated) return;

        var identity = new ClaimsIdentity(claimsIdentity);

        var currentTenantClaim = GetTenantClaim();

        if (currentTenantClaim != null)
            claimsIdentity.RemoveClaim(currentTenantClaim);

        claimsIdentity.AddClaim(new Claim(ClaimTypes.CurrentTenantId, id));

        context.Authentication.AuthenticationResponseGrant = new AuthenticationResponseGrant
            (new ClaimsPrincipal(identity), new AuthenticationProperties {IsPersistent = true});

關于如何將新的聲明持久化到 cookie 上有什么想法嗎?

Any ideas on how to persist the new claims to the cookie?

推薦答案

我已將聲明添加到錯誤的身份.必須將它們添加到身份變量而不是 claimIdentity.

I've added the claims to the wrong Identity. They had to be added to the identity variable instead of the claimsIdentity.

工作代碼:

        var claimsIdentity = (ClaimsIdentity) context.Authentication.User.Identity;
        if (!claimsIdentity.IsAuthenticated) return;

        var identity = new ClaimsIdentity(claimsIdentity);

        var currentTenantClaim = GetTenantClaim(identity);

        if (currentTenantClaim != null)
            identity.RemoveClaim(currentTenantClaim);

        identity.AddClaim(new Claim(ClaimTypes.CurrentTenantId, id));

        context.Authentication.AuthenticationResponseGrant = new AuthenticationResponseGrant
            (new ClaimsPrincipal(identity), new AuthenticationProperties {IsPersistent = true});

這篇關于更新 ClaimsPrincipal 中的聲明的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進行身份驗證并跨請求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權不起作用)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護進程或服務器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發技
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
Getting access token using email address and app password from oauth2/token(使用電子郵件地址和應用程序密碼從 oauth2/token 獲取訪問令牌)
New Azure AD application doesn#39;t work until updated through management portal(新的 Azure AD 應用程序在通過管理門戶更新之前無法運行)
主站蜘蛛池模板: 国产精品九九九 | 妖精视频一区二区三区 | 国产精品不卡一区 | 青青草综合网 | 国产精品日韩在线观看一区二区 | 激情毛片 | 欧美一二三 | 成人精品一区亚洲午夜久久久 | 国产精品美女www爽爽爽 | 有码一区 | 亚洲成人日韩 | 国产欧美一区二区精品忘忧草 | 色.com| 性色av一区二区三区 | 性生生活大片免费看视频 | 精品毛片视频 | 亚洲成人精品在线 | 午夜免费精品视频 | 国产免费又色又爽又黄在线观看 | 国产剧情一区 | 黄色大片网站 | 国产成人99久久亚洲综合精品 | 国产高清视频一区 | av一级久久 | 欧美一区二区在线 | 中文字幕免费 | 少妇淫片aaaaa毛片叫床爽 | 国产日韩欧美在线一区 | 91成人| 一级片在线免费播放 | 午夜爱爱毛片xxxx视频免费看 | 超碰在线播 | 一区二区三区欧美 | 亚洲97| 九色网址 | 国产欧美久久精品 | 久久国产香蕉 | 欧美激情久久久 | 久久的色 | 91久久夜色精品国产网站 | 亚洲国产视频一区二区 |