繁体   English   中英

Azure函数获得登录标识

[英]Azure functions get logon identify

我对Azure函数很陌生,因此如果这是一个愚蠢的问题,我深表歉意。

我试图获取用户登录标识,以前我已经能够使用HttpContext.Current.Request.LogonUserIdentity.Name做到这一点。 我在HttpRequestMessage尝试了User.Identity,但名称始终为空。

有没有成功完成此操作的功能?

谢谢。

这取决于您的配置。 默认情况下,具有通过密钥而非用户身份验证的http触发器的函数。

有没有成功完成此操作的功能?

对于基于用户的身份验证,请转到“功能应用程序设置”,单击“平台功能”选项卡下的“网络>身份验证/授权”,如下所示:

在此处输入图片说明

您可以利用App服务支持的内置身份提供程序( Azure Active DirectoryFacebookGoogleMicrosoft AccountTwitter ),然后按照Azure App Service中的身份验证和授权来配置您的身份提供程序。

run.csx:

public static HttpResponseMessage Run(HttpRequestMessage req,TraceWriter log,ExecutionContext context)
{ 
   //return req.CreateResponse(HttpStatusCode.OK,(System.Security.Claims.ClaimsPrincipal.Current.Identity as ClaimsIdentity).Claims.Select(c => new { key = c.Type, value = c.Value }),"application/json");
   return req.CreateResponse(HttpStatusCode.OK,new { username=ClaimsPrincipal.Current.Identity.Name },"application/json"); 
}

当我通过浏览器访问https://{my-funapp-name}.azurewebsites.net/api/{HttpTrigger-functionname} ,我需要先登录,然后才能检索当前登录的用户名:

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM