An OpenAuth.Net request request is always zero.

I use the DoNetOpenAuth library and follow the example here

Authentication works, but even though I need an email, the request will be zero. In fact, it does not matter what I demand, states that the answer is always zero. Not sure what I am doing wrong, and I would appreciate your help.

Thanks in advance.

Here is my login button code

protected void btnSubmit_Click( object sender, EventArgs e )
    {
        //Login button has been pushed. Add an extension and redirect
        using (OpenIdRelyingParty openId = new OpenIdRelyingParty())
        {
            IAuthenticationRequest request = openId.CreateRequest( txtOpenID.Text );

            request.AddExtension( new ClaimsRequest
                                    {
                                        Email = DemandLevel.Require,
                                        Country = DemandLevel.Request,
                                        TimeZone = DemandLevel.Request
                                    } );

            request.RedirectToProvider();

        }
    }

Here is the page load code. The ClaimsResponse variable is always null.

protected void Page_Load( object sender, EventArgs e )
    {
        OpenIdRelyingParty openId = new OpenIdRelyingParty();
        var response = openId.GetResponse();

        //check if we're processing a request
        if(response != null)
        {
            switch ( response.Status )
            {
                case AuthenticationStatus.Authenticated:

                    //authentication worked. grab our required fields
                    var claimsResponse = response.GetExtension<ClaimsResponse>();

                    //TODO enter required fields into the database

                    break;
                case AuthenticationStatus.Canceled:
                    //TODO handle cancel
                    break;

                case AuthenticationStatus.Failed:
                    //TODO handle failed
                    break;
            }
        }
    }
+3
source share
4 answers

Finally: Problem in web.config

add

& ltconfiguration>
    & ltconfigSections>
        &ltsection name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection" requirePermission="false" allowLocation="true"/>
&lt/configSections>
&lt/configuration>

&ltdotNetOpenAuth>
&ltopenid>
&ltrelyingParty>
&ltbehaviors>
&ltadd type="DotNetOpenAuth.OpenId.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth"/>
                &lt/behaviors>
&lt/relyingParty>
&lt/openid>
&lt/dotNetOpenAuth>

, .

+4

Yahoo, Google. MVC .... , ASP.NET 2

protected void Page_Load(object sender, EventArgs e) 
{
    if (this.Request.HttpMethod == "POST")
    {
        var openid = new OpenIdRelyingParty();
        string openid_identifier = this.openid_identifier.Text;
        IAuthenticationRequest request = Openid.CreateRequest(Identifier.Parse(openid_identifier));
        var fields = new ClaimsRequest();
        fields.Email = DemandLevel.Require;
        fields.FullName = DemandLevel.Require;               
        request.AddExtension(fields);
        this.Response.ContentType = "text/html";
        request.RedirectingResponse.Send();
        return;
    }
    else
    {
        OpenIdRelyingParty openid = new OpenIdRelyingParty();
        IAuthenticationResponse response = openid.GetResponse();
        if (Request.Params["ReturnUrl"] != null)
            Session["ReturnUrl"] = Request.Params["ReturnUrl"];
        if (response != null && response.Status == AuthenticationStatus.Authenticated)
        {
            var claimUntrusted = response.GetUntrustedExtension<ClaimsResponse>();
            var claim = response.GetExtension<ClaimsResponse>();
            UserData userData = null;
            if (claim != null)
            {
                userData = new UserData();
                userData.Email = claim.Email;
                userData.FullName = claim.FullName;
            }
            //now store Forms Authorisation cookie 
            IssueAuthTicket(userData, true);
            //store ClaimedIdentifier it in Session 
            //(this would more than likely be something you would store in a database I guess
            Session["ClaimedIdentifierMessage"] = response.ClaimedIdentifier;
            //If we have a ReturnUrl we MUST be using forms authentication, 
            //so redirect to the original ReturnUrl
            if (Session["ReturnUrl"] != null)
            {
                string url = Session["ReturnUrl"].ToString();
                this.Response.Redirect(url,true);
                return;
            }
            //This should not happen if all controllers have [Authorise] used on them
            else
                throw new InvalidOperationException("There is no ReturnUrl");
        }
    }
}
+2

DoNetOpenAuth. (Scott Arnott), DotNetOpenAuth, , Google OAuth , , null.

+1

It turns out that Google does not send back any information you request. They will authenticate, but more about that. Hope this helps someone else with this issue.

0
source

Source: https://habr.com/ru/post/1752004/


All Articles