Я использую DotOpenID и хочу получить ник пользователя и идентификатор электронной почты
для запроса
protected void loginButton_Click(object sender, EventArgs e)
{
if (!openidValidator.IsValid) return; // don't login if custom validation failed.
OpenID(openid_identifier.Text);
}
private void OpenID(string Indentifier)
{
OpenIdRelyingParty openid = new OpenIdRelyingParty();
try
{
IAuthenticationRequest request = openid.CreateRequest(Indentifier);
// Send your visitor to their Provider for authentication.
ClaimsRequest fetch = new ClaimsRequest();
fetch.FullName = DemandLevel.Require;
fetch.Email = DemandLevel.Require;
request.AddExtension(fetch);
request.RedirectToProvider();
}
catch (Exception ex)
{
// The user probably entered an Identifier that
// was not a valid OpenID endpoint.
openidValidator.Text = ex.Message;
openidValidator.IsValid = false;
}
}
и за ответ
openid_identifier.Focus();
OpenIdRelyingParty openid = new OpenIdRelyingParty();
if (openid.Response != null)
{
switch (openid.Response.Status)
{
case AuthenticationStatus.Authenticated:
string email = "";
string alias = "";
ClaimsResponse fetch = openid.Response.GetExtension(typeof(ClaimsResponse)) as ClaimsResponse;
alias = fetch.Nickname;
email = fetch.Email;
if (string.IsNullOrEmpty(alias))
alias = openid.Response.ClaimedIdentifier;
if (string.IsNullOrEmpty(email))
email = openid.Response.ClaimedIdentifier;
FormsAuthentication.RedirectFromLoginPage(openid.Response.ClaimedIdentifier, chkRememberMe.Checked);
break;
case AuthenticationStatus.Canceled:
loginCanceledLabel.Visible = true;
break;
case AuthenticationStatus.Failed:
loginFailedLabel.Visible = true;
break;
}
}
но здесь я получаю исключение "Ссылка на объект не установлена на экземпляр объекта".
ClaimsResponse fetch = openid.Response.GetExtension(typeof(ClaimsResponse)) as ClaimsResponse;
alias = fetch.Nickname;
email = fetch.Email;