Azure函数应用程序: Authentication Breaks Development Portal

标签 azure azure-functions

我已将 Azure Active Directory 身份验证添加到我的函数应用程序中,但是一旦我将“请求未经身份验证时要采取的操作”设置为“使用 Azure Active Directory 登录”,函数应用程序的开发界面就会生成以下内容消息:

错误: 我们无法访问您的函数应用。您的应用程序可能遇到临时问题或无法启动。您可以检查日志或在几分钟后重试。 session ID:23a5880ec94743f5a9d3ac705515b294 时间戳:2016-11-16T08:36:54.242Z

大概添加身份验证要求会以某种方式中断对函数应用程序的访问...尽管我可以在代码编辑器中进行更改,并且它们确实生效,但我不再在日志面板中看到更新:无编译例如,输出消息。

有人知道解决这个问题的方法吗?

到目前为止,我尝试将身份验证选项保留为“允许匿名请求(无操作)”并使用以下代码:

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info("C# HTTP trigger function processed a request.");

    var user = "Anonymous";
    var claimsPrincipal = Thread.CurrentPrincipal as ClaimsPrincipal;
    if (claimsPrincipal != null && claimsPrincipal.Identity.IsAuthenticated)
    {
        user = claimsPrincipal.Identity.Name;
        log.Info($"Hello {user}");    
    }       

    return req.CreateResponse(HttpStatusCode.OK, "Hello " + user);        
}

但是,这(正确地)不会重定向到身份验证提供程序...我更希望让应用程序为我处理所有这些问题,但如果这样做意味着我看不到编译消息/日志消息,这使得很难看到发生了什么。

最佳答案

内森,

不幸的是,这是目前的一个限制,我们正在此处跟踪它:https://github.com/projectkudu/AzureFunctionsPortal/issues/794

我们目前建议您在函数中允许匿名和验证的方法。要扩展您的解决方法,您可以添加以下代码,以便在检测到匿名用户时启动登录重定向(下面的代码假设您正在使用 AAD)。

else
{
    log.Info("Received an anonymous request! Redirecting...");
    var res = req.CreateResponse(HttpStatusCode.Redirect);
    res.Headers.Location = new Uri(req.RequestUri, $"/.auth/login/aad?post_login_redirect_uri={req.RequestUri.AbsolutePath}&token_mode=session");
    return res;
}

我们知道这并不理想,感谢您在我们努力改进这一过程中的耐心等待。

谢谢!

关于Azure函数应用程序: Authentication Breaks Development Portal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40627522/

相关文章:

python - Azure:Python SDK 用于列出和计算过期的应用程序注册客户端 key

设置自定义 id 属性时的 Azure Cosmos/DocumentDB 问题

azure - 发布到 Azure 后无法将函数参数绑定(bind)到类型 TraceWriter

Azure 函数错误 - 'The Keys feature is not available because Authentication/Authorization is enabled for this Function App.'

c# - 将数组发布到 Azure Function HTTP 触发器返回 500 状态代码

c# - 如何在 Visual Studio 中打开现有的 azure 函数?

azure - C# Azure 存储从一个 blob 复制文件到另一个 blob

c# - 获取 Azure 区 block 链项目的不记名 token

azure - 在 Azure Synapse Analytics 专用 SQL 池中使用 row_number() 提高查询性能

azure - 使用 Azure 数据工厂将 DBF 转换为 CSV