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

使用 Azure Active Directory 的 Azure Function 身份驗(yàn)證

Azure Function authentication using Azure Active Directory(使用 Azure Active Directory 的 Azure Function 身份驗(yàn)證)
本文介紹了使用 Azure Active Directory 的 Azure Function 身份驗(yàn)證的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

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

我想在 Azure Functions 上啟用身份驗(yàn)證.因此,我決定使用 EasyAuth(平臺(tái)功能下的身份驗(yàn)證/授權(quán)鏈接)并成功配置身份驗(yàn)證過(guò)程.

當(dāng)我手動(dòng)登錄到 Azure Function 端點(diǎn)時(shí),身份驗(yàn)證工作.但是,當(dāng)我嘗試以編程方式訪(fǎng)問(wèn) API 時(shí),無(wú)需任何手動(dòng)用戶(hù)干預(yù),就會(huì)遇到身份驗(yàn)證問(wèn)題:

狀態(tài)碼:401,未授權(quán)

我使用以下代碼使用 clientID 和 clientSecret 從 AAD 獲取訪(fǎng)問(wèn)令牌:

AuthenticationContext context = new AuthenticationContext("https://login.windows.net/<tenant-id>");字符串鍵=<客戶(hù)端密碼>";ClientCredential cc = new ClientCredential("<client-id>", key);AuthenticationResult 結(jié)果 = context.AcquireTokenAsync("https://<AzureFunctionAppName>.azurewebsites.net/", cc).Result;返回結(jié)果.AccessToken;

然后我嘗試將在標(biāo)頭中收到的訪(fǎng)問(wèn)令牌發(fā)送到我的 API 的新請(qǐng)求:

var content = "{"on":true, "sat":254, "bri":254, "hue":10000}";var AADToken = GetS2SAccessToken();HttpClient 客戶(hù)端 = 新 HttpClient();Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AADToken);var foo = Client.PostAsync("https://<AzureFunctionAppName>.azurewebsites.net/.auth/login/aad", new StringContent(content.ToString())).Result;Console.WriteLine($"result: {foo}");

但是上面的代碼會(huì)導(dǎo)致未經(jīng)授權(quán)的調(diào)用.我不確定我做錯(cuò)了什么.

解決方案

如果你的 azure function 認(rèn)證級(jí)別是 anonymous,我們可以使用 accesstoken 直接訪(fǎng)問(wèn)你的 azure function api功能鍵也是必需的.

我通過(guò)您提到的方式獲得了訪(fǎng)問(wèn)令牌.根據(jù) Azure 資源門(mén)戶(hù) (

然后我可以直接使用訪(fǎng)問(wèn)令牌.我用郵遞員測(cè)試它.

我們也可以通過(guò)以下方式獲取easy auth token.訪(fǎng)問(wèn)token就是你拿到的token.

發(fā)布 https://xxx.azurewebsites.net/.auth/login/aad內(nèi)容類(lèi)型:應(yīng)用程序/json{access_token":eyJ0eXAiOix...rtf2H7lyUL-g34HVw"}

之后我們就可以使用get token來(lái)訪(fǎng)問(wèn)azure函數(shù)api了

注意:標(biāo)頭是x-zumo-auth:token

I wanted to enable authentication on Azure Functions. So, I decided to go with EasyAuth (Authentication/Authorization link under platform features) and was successfully able to configure the authentication process.

The authentication works when I manually sign-in to the Azure Function endpoint. But when I try to programmatically access the API, without any manual user intervention, I'm facing authentication issue:

Status Code:401, Unauthorized

I get an access token from AAD using clientID and clientSecret using the following code:

AuthenticationContext context = new AuthenticationContext("https://login.windows.net/<tenant-id>");
string key = "<client-secret>";
ClientCredential cc = new ClientCredential("<client-id>", key);
AuthenticationResult result = context.AcquireTokenAsync("https://<AzureFunctionAppName>.azurewebsites.net/", cc).Result;
return result.AccessToken;

Then I'm trying to send the Access Token received in the header for a new request to my API:

var content = "{"on":true, "sat":254, "bri":254, "hue":10000}";
var AADToken = GetS2SAccessToken();
HttpClient Client = new HttpClient();
Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AADToken);
var foo = Client.PostAsync("https://<AzureFunctionAppName>.azurewebsites.net/.auth/login/aad", new StringContent(content.ToString())).Result;
Console.WriteLine($"result: {foo}");

But the above code is resulting in unauthorized calls. I am not sure what I'm doing wrong.

解決方案

We could use the accesstoken to access the you azure function api directly, if your azure function authentication level is anonymous or function key is also required.

I get the access token with your mentioned way. According to the Azure Resources portal(https://resources.azure.com/), the default allowedAudiences is

  "https://{functionAppName}.azurewebsites.net/.auth/login/aad/callback"

So I add the https://{functionAppName}.azurewebsites.net/ as allowed aduiences

Then I can use the access token directly. I test it with postman.

We also could use the following way to get easy auth token. The access token is the token that you got.

Post https://xxx.azurewebsites.net/.auth/login/aad
Content-Type:application/json
{
    "access_token":"eyJ0eXAiOix...rtf2H7lyUL-g34HVw"
}

After that we could use the get token to access the azure function api

Note: Header is x-zumo-auth: token

這篇關(guān)于使用 Azure Active Directory 的 Azure Function 身份驗(yàn)證的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(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 訪(fǎng)問(wèn)令牌和刷新令牌) - IT屋-程序員軟件開(kāi)發(fā)技
.Net Core 2.0 - Get AAD access token to use with Microsoft Graph(.Net Core 2.0 - 獲取 AAD 訪(fǎng)問(wèn)令牌以與 Microsoft Graph 一起使用)
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調(diào)用時(shí) Azure KeyVault Active Directory AcquireTokenAsync 超時(shí))
主站蜘蛛池模板: 国产欧美性成人精品午夜 | 怡红院免费的全部视频 | 99re热这里只有精品视频 | 91精品国产综合久久久动漫日韩 | 亚洲瑟瑟 | 中文字字幕一区二区三区四区五区 | 中文字幕在线看 | 视频一区二区国产 | 欧美一区二区二区 | 自拍 亚洲 欧美 老师 丝袜 | 中文字幕在线视频免费视频 | av网站在线播放 | 久久精品99 | 精品1区2区 | 福利视频网站 | 国产电影一区二区在线观看 | 中文字幕免费在线 | 亚洲精品电影网在线观看 | 国产成人精品一区二区三区四区 | 成人在线中文字幕 | 国产色在线| 亚洲欧美自拍偷拍视频 | 91精品国产91久久久久久吃药 | 欧美日韩综合精品 | 日日想夜夜操 | 日韩成人免费视频 | 日日摸夜夜爽人人添av | 精品久久国产视频 | 午夜男人免费视频 | 91高清免费观看 | 国产精品免费在线 | 成人性视频免费网站 | 91精品久久久久久久久中文字幕 | 午夜视频在线免费观看 | 正在播放国产精品 | 亚洲免费在线观看 | 91日韩| 一区二区三区四区在线视频 | 国产欧美在线播放 | 亚洲综合二区 | 日韩免费毛片视频 |