Login with gmail account via C # .net

I am using DotNetOpenID dll to register my sample application through gmail authentication via C # .net

which i used was

protected void Page_Load(object sender, EventArgs e) { OpenIdRelyingParty rp = new OpenIdRelyingParty(); var r = rp.GetResponse(); if (r != null) { switch (r.Status) { case AuthenticationStatus.Authenticated: NotLoggedIn.Visible = false; Session["GoogleIdentifier"] = r.ClaimedIdentifier.ToString(); Response.Redirect("About.aspx"); //redirect to main page of your website break; case AuthenticationStatus.Canceled: lblAlertMsg.Text = "Cancelled."; break; case AuthenticationStatus.Failed: lblAlertMsg.Text = "Login Failed."; break; } } } protected void OpenLogin_Click(object src, CommandEventArgs e) { string discoveryUri = e.CommandArgument.ToString(); OpenIdRelyingParty openid = new OpenIdRelyingParty(); var b = new UriBuilder(Request.Url) { Query = "" }; var req = openid.CreateRequest(discoveryUri, b.Uri, b.Uri); req.RedirectToProvider(); } 

It works well when I press the gmail login button, it goes to the gmail page and authenticates as needed.

but my problem is: Authentication Status. Authenticated status was unsuccessful after authentication always, although I give the correct gmail account username and password

Waiting for a valuable response and comments.

+6
source share
2 answers

As your request. You should try this code or look at this link: Gmail Accounts for ASP.net Website Authentication

 protected void Page_Load(object sender, EventArgs e) { OpenIdAjaxRelyingParty rp = new OpenIdAjaxRelyingParty(); var response = rp.GetResponse(); if (response != null) { switch (response.Status) { case AuthenticationStatus.Authenticated: NotLoggedIn.Visible = false; Session["GoogleIdentifier"] = response.ClaimedIdentifier.ToString(); var fetchResponse = response.GetExtension<FetchResponse>(); Session["FetchResponse"] = fetchResponse; var response2 = Session["FetchResponse"] as FetchResponse; string UserName = response2.GetAttributeValue(WellKnownAttributes.Name.First) ?? "Guest"; // with the OpenID Claimed Identifier as their username. string UserEmail = response2.GetAttributeValue(WellKnownAttributes.Contact.Email) ?? "Guest"; Response.Redirect("Default2.aspx"); break; case AuthenticationStatus.Canceled: lblAlertMsg.Text = "Cancelled."; break; } } } protected void OpenLogin_Click(object sender, CommandEventArgs e) { string discoveryUri = e.CommandArgument.ToString(); OpenIdRelyingParty openid = new OpenIdRelyingParty(); var url = new UriBuilder(Request.Url) { Query = "" }; var request = openid.CreateRequest(discoveryUri); // This is where you would add any OpenID extensions you wanted var fetchRequest = new FetchRequest(); // to fetch additional data fields from the OpenID Provider fetchRequest.Attributes.AddRequired(WellKnownAttributes.Contact.Email); fetchRequest.Attributes.AddRequired(WellKnownAttributes.Name.First); fetchRequest.Attributes.AddRequired(WellKnownAttributes.Name.Last); fetchRequest.Attributes.AddRequired(WellKnownAttributes.Contact.HomeAddress.Country); request.AddExtension(fetchRequest); request.RedirectToProvider(); } 
+3
source

I am not familiar with the DotNetOpenID dll. However, I would recommend using Fiddler to collect POST data that is sent during login, and make sure that you submit the correct content to your post. C # provides the HttpWebRequest class and the HttpWebResponse class in System.Net . Is there a reason you are not using them from System.dll?

Make sure that when you return your cookies from your POST, which you put in your cookie collection for any subsequent request.

There is a good class of samples for processing requests in post that cement responds to

0
source

All Articles