Stack Exchange OpenID支持哪些额外值?

时间:2012-09-29 15:33:17

标签: c# openid stackexchange

我正在尝试获取username / display name,但我不知道支持的值是什么。我得到了emailrealname,但我不知道返回username / display name的是什么。

enter image description here

是否有关于此的文档或其他内容?

我目前的代码:

public class StackExchangeOpenID : OpenIdClient
{
    public StackExchangeOpenID()
        : base("stackexchange", "https://openid.stackexchange.com")
    {

    }

    protected override Dictionary<string, string> GetExtraData(IAuthenticationResponse response)
    {
        FetchResponse fetchResponse = response.GetExtension<FetchResponse>();
        if (fetchResponse != null)
        {
            var extraData = new Dictionary<string, string>();
            extraData.Add("email", fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.Email));
            extraData.Add("name", fetchResponse.GetAttributeValue(WellKnownAttributes.Name.FullName));

            // returned value: null
            //extraData.Add("username", fetchResponse.GetAttributeValue(WellKnownAttributes.Name.Alias));

            return extraData;
        }

        return null;
    }
    protected override void OnBeforeSendingAuthenticationRequest(IAuthenticationRequest request)
    {
        var fetchRequest = new FetchRequest();
        fetchRequest.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
        fetchRequest.Attributes.AddRequired(WellKnownAttributes.Name.FullName);

        // returned value: null
        //fetchRequest.Attributes.AddRequired(WellKnownAttributes.Name.Alias);

        request.AddExtension(fetchRequest);
    }
}

1 个答案:

答案 0 :(得分:3)

你的箭头指向的是什么不是显示名称(StackID没有显示名称的概念,你的登录名是你的电子邮件地址),而是一个可选的“虚荣ID”。

例如:

enter image description here

给我https://openid.stackexchange.com/kevin.montrose的虚荣OpenID。对于需要手动输入OpenID网址的依赖方来说,这只是一个更容易记住的别名。

电子邮件和真实姓名/全名是StackID支持查询的唯一属性,并将通过SREG或AX扩展(as seen in the code)返回。