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

使用 Azure AD 和 WebAPI 的服務到服務身份驗證

Service to service authentication using Azure AD and WebAPI(使用 Azure AD 和 WebAPI 的服務到服務身份驗證)
本文介紹了使用 Azure AD 和 WebAPI 的服務到服務身份驗證的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我創建了一個使用 Azure AD 作為標識的 .NET 核心 Web 應用程序.這一切都按預期正常工作,并且我使用 [Authroize] 裝飾的任何東西都受到保護.

我現在想要確保我的一個 API 控制器可以從外部服務訪問.

我遵循了解釋服務服務身份驗證的本教程.

一些額外的點

  • 我的網絡應用和令牌的 POST 使用相同的 AD ClientID
  • 我為每個功能(Web 和服務到服務)嘗試了不同的 AD 應用程序,但似乎沒有任何區別
  • 如果我只是在瀏覽器上執行標準登錄,API 端點會按預期解析.

感謝任何幫助!

更新:

我設法嘗試了 Daemon .NET 4.5 應用程序,它使用 UseWindowsAzureActiveDirectoryBearerToken 完美運行

守護進程服務在 .NET 4.5 上提供身份驗證服務p>

但是在我的 .NET Core 應用程序中,該中間件不可用,因此我嘗試使用 JwtBearer 中間件,但仍然收到登錄提示.

app.UseJwtBearerAuthentication(new JwtBearerOptions{觀眾 = "https://localhost:44392",授權 = "https://login.microsoftonline.com/{TENANTNAME}.onmicrosoft.com"});

如您所見,我只在 BearerOptions 中設置了 2 個屬性,但我相信它們應該足以 [Authorize] 我的 API 端點.

解決方案

POST https://login.microsoftonline.com/{CLIENTID}/oauth2/token

首先獲取token時token點不正確,我們應該使用tenantId而不是clientId.

為了解決這個問題,我建議您從 this site 解碼 access_token 以查看 aud 聲明與您在 Web API 項目中配置的 Audience 相同.

Ive created a .NET core web app which is using Azure AD for the identity. This is all working fine as expected and anything I decorate using [Authroize] is protected.

I am now wanting to secure one of my API controllers to be accessible from an external service.

I followed this tutorial which explains service-service authentication.

Service to service auth with Azure AD

Using this I have managed to request a token

POST https://login.microsoftonline.com/{TENANTID}/oauth2/token
grant_type=client_credentials
&client_id={CLIENTID}
&client_secret={CLIENTSECRET}
&resource=https%3A%2F%mydirectory.onmicrosoft.com/myappname

Running this with postman, I get the Bearer access_token so looks good.

Now if I call my web app in Postman with this bearer token on the header,

GET https://localhost:44392/api/booking
Authorization Bearer {access_token}

I get a HTML response from one the Microsoft dialogues. So it seems it is just going into the redirect loop, so I am now confused on whether I have a configuration problem in the token request, or whether my web app needs to be setup in a different way. The article here mentions something about permissions in the manifest file, but I am confused why this would be necessary?

enter link description here

Some additional points

  • My web app and the POST for the token use the same AD ClientID
  • I tried different AD Apps for each feature (Web and Service-to-Service) but didnt seem to make any difference
  • If I just perform a standard login on the browser, the API endpoint resolves as expected.

Any assistance appreciated!

Updates:

I managed to try the Daemon .NET 4.5 app and this worked flawlessly using the UseWindowsAzureActiveDirectoryBearerToken

Daemon Service to service auth on .NET 4.5

However in my .NET Core app, this middleware isn't available so I tried using JwtBearer middleware but I still get the login prompt.

app.UseJwtBearerAuthentication(new JwtBearerOptions
            {
                Audience = "https://localhost:44392",
                Authority = "https://login.microsoftonline.com/{TENANTNAME}.onmicrosoft.com"
            });

As you can see, I have only set 2 properties in the BearerOptions but I believe they should have been enough to [Authorize] my API endpoint.

解決方案

POST https://login.microsoftonline.com/{CLIENTID}/oauth2/token

First the token point is incorrect when you acquire the token, we should use tenantId instead of clientId.

And to troubleshoot this issue, I suggest that you decode the access_token from this site to see whether the aud claim in the token is same as Audience you config in the web API project.

這篇關于使用 Azure AD 和 WebAPI 的服務到服務身份驗證的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 超時)
主站蜘蛛池模板: 成人在线观看免费 | 日韩一区二区三区av | 国产一区影院 | 精品亚洲一区二区三区 | 亚洲有码转帖 | 欧美精品乱码久久久久久按摩 | 国产91精品在线 | 午夜精品福利视频 | 国产精品一区二区三区久久 | 久久精品亚洲 | 色婷婷久久| 亚洲一区二区中文字幕 | 在线观看国产视频 | 亚洲一区二区三区四区五区中文 | 日皮视频免费 | 成年视频在线观看福利资源 | 精品国产欧美一区二区三区不卡 | 欧美日韩高清一区二区三区 | 精品在线观看一区二区 | 午夜久久av| 久久青 | 超碰在线国产 | 国产麻豆一区二区三区 | 精品久久香蕉国产线看观看亚洲 | 亚洲一区在线日韩在线深爱 | 午夜国产 | 欧美日韩在线观看视频网站 | 久久不射电影网 | 成人免费精品视频 | 中文字幕日韩欧美一区二区三区 | 久久久久亚洲精品中文字幕 | 日韩一区二区三区在线观看 | 中文字幕av一区 | 水蜜桃亚洲一二三四在线 | 黄色亚洲 | 国产精品久久久久久久久久久久 | 国产农村一级片 | 亚洲h在线观看 | 在线亚州| 亚洲成人一区二区 | 久久久久综合 |