我有一个 WPF 应用程序,它必须调用通过 Azure Active Directory 保护的 http-trigger 函数。在尝试检索不记名令牌以进行进一步调用时,我得到以下响应(无论我是通过邮递员还是代码完成):
AADSTS90014:缺少必填字段“范围”
我阅读了大量不同的文章和博客文章,这些文章和博客文章解释了如何使用 Azure AD 保护 http 触发功能并通过休息请求检索不记名令牌。按照我认为最适合我的需求的一篇文章,我创建了 azure 函数应用程序、azure 函数、azure AD 配置和应用程序注册的完整设置。
之后,我只想通过发送不记名令牌和其他一些参数来使用 azure 函数并获得结果,但我在检索不记名令牌时遇到了麻烦。
代码(以防万一):
var restClient = new RestClient("https://login.microsoftonline.com/{myTenant}/oauth2/v2.0/token");
var restRequest = new RestRequest(Method.POST);
restRequest.AddHeader("content-type", "application/x-www-form-urlencoded");
restRequest.AddParameter("grant_type", "client_credentials", ParameterType.GetOrPost);
restRequest.AddParameter("client_id", "{app id from azure ad app}", ParameterType.GetOrPost);
restRequest.AddParameter("client_secret", "{generated secret}", ParameterType.GetOrPost);
restRequest.AddParameter("ressource", "https://{somefunctionname}.azurewebsites.net", ParameterType.GetOrPost);
var restResponse = restClient.Execute(restRequest);
Run Code Online (Sandbox Code Playgroud)
邮递员身体参数(x-www-form-urlencoded):
grant_type = "client_credentials"
client_id = {来自 azure 广告应用的应用 ID}
client_secret = {生成的秘密}
ressource = " https://somefunctionname.azurewebsites.net "
以及我用来获取令牌的网址: …
我正在使用 HttpTrigger 创建一个新的 azure 函数。我想实现一个天蓝色的表存储表作为输入绑定。按照 msdn 中的源代码示例,我无法确定可以在哪个 NuGet 包中找到“Table”属性。
编译问题:
找不到类型或命名空间“TableAttribute”(您是否缺少 using 指令或程序集引用?)
代码行,导致问题:
public static async Task<IActionResult>
Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
[Table("AzureWebJobsHostLogscommon")] CloudTable cloudTable,
ILogger log)
Run Code Online (Sandbox Code Playgroud)
我所指的 MSDN 中的源代码示例可以在这里找到:
和这里:
第二个示例还显示了 using 指令。但即使在复制示例时,表属性也无法正确解析。
我还看到了这个 stackoverflow 线程:
但第一个解决方案对我来说只是一种解决方法,因为表存储连接是在函数执行期间完成的,而不是作为输入绑定。如果您看到第二个建议的解决方案,它会显示与 MSDN 中相同的代码。
这是我的代码:
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage.Table;
using System;
using System.Net;
using System.Threading.Tasks;
namespace TableStorageIntegration.HTTPTrigger
{
public static class Function1
{
[FunctionName("DoSomething")]
public static async …Run Code Online (Sandbox Code Playgroud)