1
我正在使用以下代码,我从网上找到用于验证用户的网站。但是用户必须点击一个按钮才能登录到该网站,即使他们登录到Gmail。我想要做的是当他们登录到Gmail时自动登录他们。 那么我如何修改下面的代码来做到这一点?如何使用DotNetOpenAuth来检测用户是否登录到谷歌
static string openidurl = "https://www.google.com/accounts/o8/id";
protected void Page_Load(object sender, EventArgs e)
{
//The Response
OpenIdRelyingParty openid = new OpenIdRelyingParty();
var response = openid.GetResponse();
if (response != null)
{
switch (response.Status)
{
case AuthenticationStatus.Authenticated:
var fetch = response.GetExtension<FetchResponse>();
string email = "";
if (fetch != null)
{
email = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email);
}
break;
}
}
}
private void CreateRequest()
{
using (OpenIdRelyingParty openid = new OpenIdRelyingParty())
{
IAuthenticationRequest request = openid.CreateRequest(openidurl);
var fetch = new FetchRequest();
fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
request.AddExtension(fetch);
// Send your visitor to their Provider for authentication.
request.RedirectToProvider();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
CreateRequest();
}
我想用OpenID并不是解决我的问题的正确方法。 在stackoverflow网站本身有一个Gmail登录选项。由于我已经登录到gmail,它没有要求再次登录到gmail。 我该如何做类似的事情?我正在使用ASP .NET – Janaka 2011-04-20 07:46:41
@Janaka - 不,没有。有一种方法可以使用Google作为OpenId提供商登录到StackOverflow。我相信你所描述的是由图书馆和谷歌自动完成的(所以谷歌知道你已经登录,因此经过认证并告诉你没有你需要再次登录的你是谁)。 – Oded 2011-04-20 07:48:41
好的,谢谢。我的问题是为什么自动登录不会发生,即使我登录到Gmail。 原因是我从Crome登录到Gmail,我正在使用IE调试应用程序 – Janaka 2011-04-20 07:59:01