Gmail credentials for Authentication of ASP.net Website

ⅰ亾dé卋堺 提交于 2019-12-13 10:31:50

问题


I have two textboxes for username and password now i want users to enter their company email Id and password (Username and password is powered by google ,webserver is google) and log in to the ASP.net website.Create session of username and password .Futher i want the user to able to send the email from asp.net website using same gmail credential.Thank you in advance and any type of help will be appreciated.


回答1:


You should check the OpenId library for C#.

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

This will give you a good start. This way, the user won't have to use his password directly and will be redirect to the provider that will grant authentification for your site.




回答2:


Answer which i wanted is this and this code works fine.and I am not storing 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 have further doubt is how to get the username by which the user is logged to create session ...???It can be done i have seen it somewhere...




回答3:


Nah, Google won't let you do that. You'll have to do something similar to what StackOverflow is doing (provide OpenID functionality to authenticate at google.com).



来源:https://stackoverflow.com/questions/9199958/gmail-credentials-for-authentication-of-asp-net-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!