C# ClaimsPrincipal.Current.Identity.Name从客户端进行身份验证时为空,在浏览器中正常

C# ClaimsPrincipal.Current.Identity.Name从客户端进行身份验证时为空,在浏览器中正常,c#,azure-functions,C#,Azure Functions,我有以下Azure函数 #r "Newtonsoft.Json" using Newtonsoft.Json.Linq; using System.Net; using System.Security.Claims; public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log) { try { JObject pJOtClaims

我有以下Azure函数

#r "Newtonsoft.Json"

using Newtonsoft.Json.Linq;
using System.Net;
using System.Security.Claims;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    try
    {
        JObject pJOtClaims = new JObject();
        foreach(Claim curClaim in  ClaimsPrincipal.Current.Identities.First().Claims)
        {
            pJOtClaims.Add(curClaim.Type, new JValue(curClaim.Value));
        }
        return(req.CreateResponse(HttpStatusCode.OK, $"{pJOtClaims.ToString(Newtonsoft.Json.Formatting.None)}"));
    }
    catch(Exception ex)
    {
        return(req.CreateResponse(HttpStatusCode.OK, $"{ex.Message}"));
    }
}
不幸的是,这些都不包括我需要的Facebook电子邮件地址。我已经为Facebook身份验证配置启用了“电子邮件”范围。你知道怎么做吗


尼克。

好吧,我还没有找到我想要的确切解决方案,但这应该可以让我通过。从技术上讲,我只需要注册期间的电子邮件地址,然后我就可以使用稳定的sid作为我确实获得的身份的一部分。因此,我所做的是将x-zumo-auth头传递给“.auth/me”方法,获取所需的属性。我在用这个方法

    public static async Task<String> GetAuthProviderParam(String iAuthMeURL,
        String iXZumoAUth,
        String iParamKey)
    {
        using (HttpClient pHCtClient = new HttpClient())
        {
            pHCtClient.DefaultRequestHeaders.Add("x-zumo-auth", iXZumoAUth);
            String pStrResponse = await pHCtClient.GetStringAsync(iAuthMeURL);
            JObject pJOtResponse = JObject.Parse(pStrResponse.Trim(new Char[] { '[', ']' }));
            if(pJOtResponse[iParamKey] != null)
            {
                return (pJOtResponse[iParamKey].Value<String>());
            }
            else
            {
                throw new KeyNotFoundException(String.Format("A parameter with the key '{0}' was not found.", iParamKey));
            }
        }
    }

我还应该指出,CurrentPrincipal.Current.Identifies枚举只包含一个标识。
    public static async Task<String> GetAuthProviderParam(String iAuthMeURL,
        String iXZumoAUth,
        String iParamKey)
    {
        using (HttpClient pHCtClient = new HttpClient())
        {
            pHCtClient.DefaultRequestHeaders.Add("x-zumo-auth", iXZumoAUth);
            String pStrResponse = await pHCtClient.GetStringAsync(iAuthMeURL);
            JObject pJOtResponse = JObject.Parse(pStrResponse.Trim(new Char[] { '[', ']' }));
            if(pJOtResponse[iParamKey] != null)
            {
                return (pJOtResponse[iParamKey].Value<String>());
            }
            else
            {
                throw new KeyNotFoundException(String.Format("A parameter with the key '{0}' was not found.", iParamKey));
            }
        }
    }
    if(req.Headers.Contains("x-zumo-auth"))
    {
        String pStrXZumoAuth = req.Headers.GetValues("x-zumo-auth").First();
        String pStrParam = await FunctionsHelpers.GetAuthProviderParam("https://appname.azurewebsites.net/.auth/me",
            pStrXZumoAuth,
            "user_id");
        //pStrParam = user_id
    }