久久久久久久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的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號(hào)..

我正在嘗試創(chuàng)作一個(gè)網(wǎng)站,該網(wǎng)站使用 AzureAD 對(duì)用戶進(jìn)行身份驗(yàn)證以訪問 UI 以創(chuàng)作數(shù)據(jù)庫中的項(xiàng)目.而且我還希望其他服務(wù)可以通過不記名令牌調(diào)用此 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 方案對(duì)用戶進(jìn)行身份驗(yàn)證,但對(duì)同一 WEB API(在差異路由下)的服務(wù)由承載進(jìn)行身份驗(yàn)證.或者擁有除兩者之外的所有路線.兩者都有效

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

推薦答案

最終通過創(chuàng)建一個(gè)策略方案來解決這個(gè)問題,該方案根據(jù)存在的 auth 標(biāo)頭在兩個(gè)模式之間切換:

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));

這篇關(guān)于如何將 AzureAD 和 AzureADBearer 添加到 asp.net core 2.2 web api的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進(jìn)行身份驗(yàn)證并跨請(qǐng)求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權(quán)不起作用)
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(如何獲取守護(hù)進(jìn)程或服務(wù)器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發(fā)技
.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(異步調(diào)用時(shí) Azure KeyVault Active Directory AcquireTokenAsync 超時(shí))
主站蜘蛛池模板: 一级做a | 蜜桃日韩 | 亚洲精品电影网在线观看 | 午夜影院在线观看 | 亚洲欧美日韩中文字幕一区二区三区 | 91精品国产综合久久久久久 | 日韩一区二区三区在线观看 | 国内精品一区二区 | av在线免费观看不卡 | 国产精品久久a | 国产欧美精品一区二区色综合朱莉 | 日韩精品久久久久久 | 不卡的av电影| 99亚洲精品 | 久久夜视频 | 成人免费小视频 | 国产区一区 | 福利网站在线观看 | 性欧美hd| av片在线免费看 | 国产在线麻豆精品入口 | 狠狠爱网址 | 国产网站在线免费观看 | 免费色网址 | 日p视频免费看 | 欧美极品少妇xxxxⅹ免费视频 | 欧美高清视频 | 黄在线 | 欧美日韩中文国产一区发布 | 中文字幕中文字幕 | 国产区在线| www视频在线观看 | 九色国产 | 一区二区三区四区视频 | 欧美伊人久久久久久久久影院 | 一区二区三区欧美在线 | 久久综合伊人 | 一区二区福利视频 | 亚洲日本免费 | 先锋影音资源网站 | 91麻豆精品国产91久久久久久 |