Gmail Credentials for ASP.net Website Authentication

I have two text fields for the username and password, now I want users to enter their company email id and password (the username and password work from Google, the web server is Google) and go to ASP.net. Create a username and password session. I want the user to be able to send email from asp.net using the same gmail credentials. Thanks in advance and any help would be appreciated.

-1
source share
3 answers

The answer I need is this and this code works fine. And I did not store the password anywhere in the session and database.

<form id="form1" runat="server"> <div id="loginform"> <div id="NotLoggedIn" runat="server"> Log in with <img src="http://www.google.com/favicon.ico" /> <asp:Button ID="btnLoginToGoogle" Runat="server" Text="Google" OnCommand="OpenLogin_Click" CommandArgument="https://www.google.com/accounts/o8/id" /> <p /><asp:Label runat="server" ID="lblAlertMsg" /> </div> </div> </form> using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using DotNetOpenAuth.OpenId; using DotNetOpenAuth.OpenId.RelyingParty; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { OpenIdAjaxRelyingParty rp = new OpenIdAjaxRelyingParty(); var r = rp.GetResponse(); if (r != null) { switch (r.Status) { case AuthenticationStatus.Authenticated: NotLoggedIn.Visible = false; Session["GoogleIdentifier"] = r.ClaimedIdentifier.ToString(); 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 b = new UriBuilder(Request.Url) { Query = "" }; var req = openid.CreateRequest(discoveryUri, b.Uri, b.Uri); req.RedirectToProvider(); } } 

but I still doubt how to get the username with which the user logs in to create a session ... ??? Maybe I saw him somewhere ...

+2
source

You should check out the OpenId library for C #.

http://code.google.com/p/dotnetopenid/

This will give you a good start. Thus, the user does not have to directly use his password and will be redirected to the provider, which will provide authentication for your site.

+2
source

No, Google will not allow you to do this. You will need to do something similar to what StackOverflow does (provide OpenID functions for authentication on google.com).

0
source

All Articles