views:

81

answers:

0

I keep getting a NullReferenceException when I try to use Yahoo.

Google works fine.

Yahoo also has an extra page that asks if I want to continue because my site is not trusted. Don't know if that's what it doesn't work or not.

This kicks it off when you click the Google or Yahoo Button, url is http://yahoo.com or https://www.google.com/accounts/o8/id depending on the button you click:

protected void Login(string url)
    {
        if (!this.Page.IsValid)
        {
            return; // don't login if custom validation failed.
        }
        try
        {
            using (OpenIdRelyingParty openid = new OpenIdRelyingParty())
            {
                //IAuthenticationRequest request = openid.CreateRequest(this.openIdBox.Text);
                IAuthenticationRequest request = openid.CreateRequest(url);

                // This is where you would add any OpenID extensions you wanted
                // to include in the authentication request.
                request.AddExtension(new ClaimsRequest
                {
                    Country = DemandLevel.Request,
                    Email = DemandLevel.Request,
                    Gender = DemandLevel.Require,
                    PostalCode = DemandLevel.Require,
                    TimeZone = DemandLevel.Require,
                });

                // Send your visitor to their Provider for authentication.
                request.RedirectToProvider();
            }
        }
        catch (ProtocolException ex)
        {
            // The user probably entered an Identifier that
            // was not a valid OpenID endpoint.
            //this.openidValidator.Text = ex.Message;
            //this.openidValidator.IsValid = false;
        }
    }

And this is PageLoad():

                    OpenIdRelyingParty openid = new OpenIdRelyingParty();
                    IAuthenticationResponse response = openid.GetResponse(); //NullReferenceException  HERE
                    if (response != null)
                    {
                        switch (response.Status)
                        {
                            case AuthenticationStatus.Authenticated:
                                FormsAuthentication.RedirectFromLoginPage(response.ClaimedIdentifier, false);
                                break;
                            case AuthenticationStatus.Canceled:
                                this.loginCanceledLabel.Visible = true;
                                break;
                            case AuthenticationStatus.Failed:
                                this.loginFailedLabel.Visible = true;
                                break;
                        }
                    }

StackTrace:

   at DotNetOpenAuth.OpenId.Extensions.ProviderAuthenticationPolicy.PolicyResponse.DotNetOpenAuth.Messaging.IMessageWithEvents.OnReceiving()
   at DotNetOpenAuth.OpenId.ChannelElements.ExtensionsBindingElement.<GetExtensions>d__a.MoveNext()
   at DotNetOpenAuth.OpenId.ChannelElements.ExtensionsBindingElement.ProcessIncomingMessage(IProtocolMessage message)
   at DotNetOpenAuth.Messaging.Channel.ProcessIncomingMessage(IProtocolMessage message)
   at DotNetOpenAuth.OpenId.ChannelElements.OpenIdChannel.ProcessIncomingMessage(IProtocolMessage message)
   at DotNetOpenAuth.Messaging.Channel.ReadFromRequest(HttpRequestInfo httpRequest)
   at DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.GetResponse(HttpRequestInfo httpRequestInfo)
   at DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.GetResponse()
   at Login_Default.Page_Load(Object sender, EventArgs e) in c:\Documents and Settings\Admin\My Documents\Visual Studio 2008\WebSites\Contestables\Login\Default.aspx.cs:line 21
   at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)