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

Azure AD API 請求 401 未經(jīng)授權(quán)

Azure AD API request 401 Unauthorized(Azure AD API 請求 401 未經(jīng)授權(quán))
本文介紹了Azure AD API 請求 401 未經(jīng)授權(quán)的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

我在啟用了 Azure AD 身份驗(yàn)證的 Azure 網(wǎng)站上運(yùn)行了一個標(biāo)準(zhǔn) Web API,當(dāng)在瀏覽器中瀏覽 API 時,我能夠通過瀏覽器登錄并獲得對 API 的訪問權(quán)限.

I have a standard Web API running on an Azure website with Azure AD authentication enabled, when browsing to the API in a browser I am able to login via the browser and gain access to the API.

然而,WPF 桌面應(yīng)用程序在提交請求時收到未經(jīng)授權(quán)響應(yīng):

The WPF desktop application however is receiving an Unauthorized response when submitting the request:

var authContext = new AuthenticationContext(authority, new FileCache());
var accessToken = await authContext.AcquireTokenAsync(apiResourceid, clientId, redirectUri,
                    new PlatformParameters(PromptBehavior.Auto));
// accessToken is valid

var apiUrl = "https://example.azurewebsites.net/api/list";
var request = new HttpRequestMessage(HttpMethod.Get, apiUrl);
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.AccessToken);
var response = await httpClient.SendAsync(request);

認(rèn)證成功,調(diào)試時可以看到用戶信息.

The authentication is successfull and I can see the User info when debugging.

我無權(quán)訪問 Azure 帳戶,但我確信 Service AD 應(yīng)用程序配置正確,允許訪問客戶端 AD 應(yīng)用程序,就像在備用帳戶(未正確配置)上測試時一樣,AuthenticationContext.AcquireTokenAsync 方法失敗.

I do not have access to the Azure account but am confident the Service AD application is configured correctly to allow access to the Client AD application as when testing on an alternate account (not configured correctly) the AuthenticationContext.AcquireTokenAsync method was failing.

我確實(shí)注意到 AuthenticationResult.ExpiresOn 總是在過去,但看不到延長它的方法,這應(yīng)該是未來的日期嗎? - (時間是當(dāng)然UTC)

I did notice that the AuthenticationResult.ExpiresOn is always in the past but see no way of extending it, should this be a future date? - (Time is of course UTC)

請求:

GET https://example.azure
websites.net/api/categorisation HTTP/1.1
Authorization: Bearer eyJ0eXAiO...
Host: example.azurewebsites.net

回復(fù):

HTTP/1.1 401 Unauthorized
Content-Length: 58
Content-Type: text/html
Server: Microsoft-IIS/8.0
WWW-Authenticate: Bearer realm="example.azurewebsites.net"
X-Powered-By: ASP.NET
Set-Cookie: ARRAffinity=e35f2977dba55e6708887e762940f75c2a0fcb0a9df4e1cbe0d3f10a614c59b8;Path=/;Domain=example.azurewebsites.net
Date: Fri, 08 Jul 2016 07:51:13 GMT

You do not have permission to view this directory or page.

更新:

我在我有權(quán)訪問的 Azure 帳戶中重新創(chuàng)建了環(huán)境,但仍然收到未經(jīng)授權(quán)的響應(yīng)(在瀏覽器中可以正常工作).

I have recreated the environment in an Azure account I have access to and still receive an Unauthorised response (works fine in a browser).

推薦答案

問題似乎與 Azure 網(wǎng)站中的身份驗(yàn)證/授權(quán)"選項(xiàng)有關(guān),啟用后,Web Api 將不接受使用身份驗(yàn)證標(biāo)頭的請求.禁用該選項(xiàng)并將 Owin 庫與 Azure AD 一起使用提供了所需的解決方案.

The issue appears to be with the "Authentication / Authorization" option in Azure Websites, when enabled the Web Api will not accept requests using the Authentication header. Disabling the option and using the Owin library alongside Azure AD has provided the solution required.

這篇關(guān)于Azure AD API 請求 401 未經(jīng)授權(quán)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(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)證并跨請求保留自定義聲明)
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)用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
主站蜘蛛池模板: 少妇精品亚洲一区二区成人 | 91精产国品一二三区 | 久久69精品久久久久久国产越南 | 亚洲性视频 | 久久久久久久成人 | 国产精品99久久久精品免费观看 | 欧美一级毛片久久99精品蜜桃 | 午夜免费看 | 日韩黄色免费 | 成人免费一级 | 久久99精品久久久久久国产越南 | 中文字幕日韩一区 | 欧美亚洲日本 | 精品美女 | 人人爽人人草 | 欧美日韩在线一区二区 | 狠狠干网站| 国产精品亚洲精品日韩已方 | 国产色婷婷精品综合在线播放 | 日本精品久久 | 亚欧性视频 | 狠狠爱视频 | 中文字幕视频在线 | 日韩在线电影 | 国产精品久久久久久亚洲调教 | 一级黄色片网站 | 日日骚网 | 黄色一级免费看 | 国产精品中文字幕在线 | 欧美一区二区三区小说 | 亚洲综合二区 | 亚洲免费av一区 | 久久亚洲国产精品 | 国产精品一区二区在线 | 久久精品亚洲国产奇米99 | 大久| 蜜臀久久99精品久久久久野外 | 九九在线视频 | 美女视频h| 久久成人精品一区二区三区 | 欧美a区|