【发布时间】:2021-02-16 08:21:56
【问题描述】:
我在我的应用服务中使用 http trigger azure 函数。我希望这个 http 触发 azure 函数不能公开访问,只能从应用服务访问。
目前我已经为 http 触发功能创建了主机密钥,我正在使用它来验证请求。
我应该使用哪种身份验证方法?任何想法。
Azure 函数:
public static class RemoveSubscriptionsForPayers
{
[FunctionName(nameof(RemoveSubscriptionsForPayers))]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
[Inject] ILoggingService loggingService,
[Inject] ICommandValidator commandValidator,
[Inject] ICommandHandler<ResultDto,RemoveSubscriptionsForPayersCommand> commandHandler)
{
var logger = new Logger(loggingService);
try
{
IActionResult actionResult = null;
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
logger.Info($"RemoveSubscriptionsForPayersCommand received on {nameof(RemoveSubscriptionsForPayers)}");
var command = requestBody.AsPoco<RemoveSubscriptionsForPayersCommand>();
if (commandValidator.Validate<RemoveSubscriptionsForPayersCommand>(req, command, new RemoveSubscriptionsForPayersCommandValidator(), logger, ref actionResult))
{
var response =await commandHandler.HandleAsync(command, logger);
actionResult = new OkObjectResult(response);
}
return actionResult;
}
catch (Exception ex)
{
logger.Error($"Exception while processing {nameof(RemoveSubscriptionsForPayers)}", ex,
nameof(RemoveSubscriptionsForPayers));
throw;
}
}
}
【问题讨论】:
-
Azure AD 不能解决您的问题吗?
-
谢谢!期待你的答复。我还没试过。
标签: azure authentication azure-functions