久久久久久久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级黄色片视频 | 中文字幕二区 | 久久99深爱久久99精品 | 国产精品欧美大片 | 日本成人在线网址 | 毛片区| 国产在线播 | 国产999精品久久久久久 | 日韩福利电影 | 欧美日韩久久 | 看av网址 | 欧美精品一二三 | 欧美精品在线一区二区三区 | 午夜男人免费视频 | 日日噜 | 日韩三级视频 | 卡通动漫第一页 | 午夜免费在线观看 | 亚洲天堂一区二区 | 国产精品久久久久久久久久免费看 | 国产精品免费播放 | 99国产精品视频免费观看一公开 | 日日干日日操 | 欧美v在线观看 | 久久国产一区二区三区 | 国产精品国产a级 | 国产成人99久久亚洲综合精品 | 91佛爷在线观看 | 久久久久9999亚洲精品 | 在线只有精品 | 欧美5区| 91av视频在线 | 国产高清精品一区二区三区 | 欧美日高清| 久久久久久综合 | 色资源站| 日本精品一区二区三区视频 | 人成在线视频 | 日韩一区在线播放 | 天天操夜夜操免费视频 |