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

使用 Azure Active Directory 的 Azure Function 身份驗證

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

問題描述

限時送ChatGPT賬號..

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

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

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

我使用以下代碼使用 clientID 和 clientSecret 從 AAD 獲取訪問令牌:

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

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

var content = "{"on":true, "sat":254, "bri":254, "hue":10000}";var AADToken = GetS2SAccessToken();HttpClient 客戶端 = 新 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}");

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

解決方案

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

我通過您提到的方式獲得了訪問令牌.根據(jù) Azure 資源門戶 (

然后我可以直接使用訪問令牌.我用郵遞員測試它.

我們也可以通過以下方式獲取easy auth token.訪問token就是你拿到的token.

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

之后我們就可以使用get token來訪問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 身份驗證的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)行身份驗證并跨請求保留自定義聲明)
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 超時)
主站蜘蛛池模板: 亚洲精品久久久久久久久久久久久 | 日本高清在线一区 | 久久久国产精品一区 | 亚洲国产二区 | 欧美成年网站 | 色综合久久天天综合网 | 在线视频一区二区三区 | 欧美成人激情视频 | 久久国产一区二区 | 在线视频 欧美日韩 | 成人欧美一区二区三区1314 | 久久亚洲国产精品 | 91精品国产综合久久婷婷香蕉 | 一区二区三区四区视频 | 免费黄色大片 | 国产三级精品三级在线观看四季网 | 中国黄色毛片视频 | 国产精品视频网址 | 国产在线视频一区二区董小宛性色 | 伊人久久综合 | 免费观看黄网站 | 欧美一区二区三区一在线观看 | 男女深夜网站 | 国产亚洲精品精品国产亚洲综合 | 久久99精品久久久久久国产越南 | 日韩三极 | 国产精品国产三级国产aⅴ无密码 | 久久大陆 | 天天亚洲 | 久久国产视频网 | 国产精品亚洲综合 | 91久久国产综合久久91精品网站 | 中文字幕免费在线 | 成人水多啪啪片 | 久久综合狠狠综合久久综合88 | 黄色av免费| 岛国视频| 色综合久久天天综合网 | 国产精品久久久久久久7电影 | 狠狠综合网 | a在线免费观看 |