久久久久久久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 應用程序在通過管理門戶更新之前無法運行)
主站蜘蛛池模板: 亚洲欧美久久 | 理论片免费在线观看 | 久久精品日产第一区二区三区 | 日本在线网站 | 日日操夜夜摸 | 国产精品久久久久久吹潮日韩动画 | 成人在线观看中文字幕 | 欧美日韩一区精品 | 伊人网影院 | 7777在线视频免费播放 | 美女在线视频一区二区三区 | 日韩影院在线 | 范冰冰一级做a爰片久久毛片 | 国产黄色大片在线观看 | 午夜免费在线电影 | 成人免费福利视频 | 欧美色专区 | 欧美一区二区免费 | 中文字幕一区在线观看视频 | 国产亚洲久 | 奇米四色影视 | 亚洲精品区 | 国产激情在线播放 | 日本一区二区视频 | 成人影院在线观看 | 久久精品在线 | 成人一区二区在线 | 嫩草视频免费 | 成人精品视频在线观看 | 国产二区精品视频 | 拍真实国产伦偷精品 | 成人综合视频在线 | 日韩av成人在线观看 | av在线成人 | 欧美亚洲国产一区二区三区 | 国产一区欧美 | 久久久www成人免费精品 | 久久久蜜臀国产一区二区 | 亚洲a视频| 午夜精品久久久久久久久久久久久 | 亚洲精品一区中文字幕乱码 |