0

I am using DotOpenID and I want to fetch user's nickname and email ID

for request

 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;
    }
}

and for response

 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;

        }
    }

but I am getting exception at here "Object reference not set to an instance of an object".

 ClaimsResponse fetch = openid.Response.GetExtension(typeof(ClaimsResponse)) as ClaimsResponse;
                alias = fetch.Nickname;
                email = fetch.Email;
Govind Malviya
  • 13,627
  • 17
  • 68
  • 94

1 Answers1

2

Possibly duplicate:
claimsResponse Return Null
https://stackoverflow.com/questions/3265678/dotnetopenid-claimsresponse-always-null

The first one has the following answer by Andrew Arnott, which might be related:

It looks like you're doing everything right. At this point it depends on the Provider you're using. Which one are you testing against? Some don't support Simple Registration (ClaimsRequest) at all. Others only support it for whitelisted RPs. Then others don't support it when your RP is at "localhost".

My advice: test against myopenid.com, as that seems to have good, consistent behavior and support for the Simple Registration extension. But your RP must always be prepared to receive null for ClaimsResponse, since you're never guaranteed the OP will give you anything.

Even if you get a non-null result, individual fields that you asked for (even if you marked them required) may be null or blank.

Community
  • 1
  • 1
Danny Tuppeny
  • 40,147
  • 24
  • 151
  • 275