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

如何將 AzureAD 和 AzureADBearer 添加到 asp.net core 2.

How to add AzureAD AND AzureADBearer to asp.net core 2.2 web api(如何將 AzureAD 和 AzureADBearer 添加到 asp.net core 2.2 web api)
本文介紹了如何將 AzureAD 和 AzureADBearer 添加到 asp.net core 2.2 web api的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在嘗試創作一個網站,該網站使用 AzureAD 對用戶進行身份驗證以訪問 UI 以創作數據庫中的項目.而且我還希望其他服務可以通過不記名令牌調用此 API.

I'm trying to author a website that uses AzureAD to authenticate users to access UIs to author items in a DB. And I also want this API to be callable by other services via a bearer token.

services.AddAuthentication(o => {
                    o.DefaultScheme = AzureADDefaults.BearerAuthenticationScheme;
                    o.DefaultAuthenticateScheme = AzureADDefaults.AuthenticationScheme;
                })
                .AddAzureAD(options => Configuration.Bind("AzureAd", options))
                .AddAzureADBearer(options => Configuration.Bind("AzureAd", options));

我希望使用 AzureAD 方案對用戶進行身份驗證,但對同一 WEB API(在差異路由下)的服務由承載進行身份驗證.或者擁有除兩者之外的所有路線.兩者都有效

I want users to be authenticated using the AzureAD scheme, but services to the same WEB API (under a dif route) to be authenticated by the bearer. Or have all routes except both. Either works

推薦答案

最終通過創建一個策略方案來解決這個問題,該方案根據存在的 auth 標頭在兩個模式之間切換:

ended up solving this by creating a policy scheme which toggles between the two schemas depending on the auth header present:

// add azure ad user and service authentication
            services
                .AddAuthentication("Azures")
                .AddPolicyScheme("Azures", "Authorize AzureAd or AzureAdBearer", options =>
                {
                    options.ForwardDefaultSelector = context =>
                    {
                        var authHeader = context.Request.Headers["Authorization"].FirstOrDefault();
                        if (authHeader?.StartsWith("Bearer") == true)
                        {
                            return AzureADDefaults.JwtBearerAuthenticationScheme;
                        }

                        return AzureADDefaults.AuthenticationScheme;
                    };
                })
                .AddAzureADBearer(options => config.Bind("AzureAdBearer", options))
                .AddAzureAD(options => config.Bind("AzureAd", options));

這篇關于如何將 AzureAD 和 AzureADBearer 添加到 asp.net core 2.2 web api的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 令牌授權不起作用)
ASP Core Azure Active Directory Login use roles(ASP Core Azure Active Directory 登錄使用角色)
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屋-程序員軟件開發技
.Net Core 2.0 - Get AAD access token to use with Microsoft Graph(.Net Core 2.0 - 獲取 AAD 訪問令牌以與 Microsoft Graph 一起使用)
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
主站蜘蛛池模板: 日本加勒比在线观看 | 日本黄a三级三级三级 | 黄色a毛片| 黑人巨大猛烈捣出白浆 | 久久久久久久免费视频 | 一级片久久 | 天天干网| 日韩精品免费在线观看 | 99热这里都是精品 | 日韩和的一区二区 | 国产欧美日韩一区二区三区 | av网站免费在线观看 | 丁香九月婷婷 | 中文字幕不卡在线 | 日韩毛片在线 | 青青草久草| 国产精品成人一区二区三区 | 久久不射网| 欧美九九九 | 免费v片在线观看 | 一区二区精品 | 97视频在线观看免费 | 久久av影院 | 亚洲一区二区久久 | 色站综合| 国产精品福利视频 | 久久精品久久久精品美女 | 色婷婷网 | 国产成人精品一区二区 | www.久久久| 精品国产aⅴ麻豆 | 国产高清av | 中文字幕av网站 | 国内精品一区二区三区 | 一区二区免费看 | 久久免费视频观看 | 国产精品一二三 | 国产精品三| 黄网站免费观看 | 自拍偷在线精品自拍偷无码专区 | 欧美激情五月 |