Google账户登录服务
2009-10-04 22:28
197 查看
现在有些网站有了Google账户登录的功能,如下图,这样的登录方式其实对用户是有益的。只要我有个google账号,就能登录有利用Google这个登录服务的网站。此功能详解请参考
/// <summary>
/// 提供google账户的登录
/// </summary>
public class GoogleLogin : ILoginService
{
string urlAuthSubRequest = "https://www.google.com/accounts/AuthSubRequest?";
string next = ILoginService.WebsiteUrl() + "/Auth/Handle.aspx";
string scope = "http://www.google.com/m8/feeds/contacts/default/thin?max-results=0";
string urldata = "";
/// <summary>
/// 生成登录用的url
/// </summary>
/// <returns></returns>
public override string getLoginUrl()
{
return urlAuthSubRequest + "next=" + HttpUtility.UrlEncode(next) + "&scope=" + HttpUtility.UrlEncode(scope);
}
/// <summary>
/// 得到Google账户的Email地址和姓名
/// </summary>
/// <param name="page"></param>
/// <returns></returns>
public override string[] parseHandle(HttpContext page)
{
urldata = scope;
string[] ret = new string[2];
try
{
string token = page.Request["token"];
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(urldata));
request.Headers.Add("Authorization", "AuthSub token=" + token);
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
XmlDocument doc = new XmlDocument();
if (response != null)
{
string account = string.Empty, name = string.Empty;
doc.Load(response.GetResponseStream());
XmlNode node = doc.SelectSingleNode("*/*[local-name()='id']");
if (node != null)
{
account = node.InnerText; //Email地址
}
node = doc.SelectSingleNode("*/*[local-name()='author']/*[local-name()='name']");
if (node != null)
{
name = node.InnerText; //姓名
}
ret[0] = account;
ret[1] = name;
return ret;
}
else return ret;
}
catch (Exception ex)
{
new MyException("GoogleLogin", ex.ToString());
return new string[] { "", "" };
}
}
}
/// <summary>
/// 提供google账户的登录
/// </summary>
public class GoogleLogin : ILoginService
{
string urlAuthSubRequest = "https://www.google.com/accounts/AuthSubRequest?";
string next = ILoginService.WebsiteUrl() + "/Auth/Handle.aspx";
string scope = "http://www.google.com/m8/feeds/contacts/default/thin?max-results=0";
string urldata = "";
/// <summary>
/// 生成登录用的url
/// </summary>
/// <returns></returns>
public override string getLoginUrl()
{
return urlAuthSubRequest + "next=" + HttpUtility.UrlEncode(next) + "&scope=" + HttpUtility.UrlEncode(scope);
}
/// <summary>
/// 得到Google账户的Email地址和姓名
/// </summary>
/// <param name="page"></param>
/// <returns></returns>
public override string[] parseHandle(HttpContext page)
{
urldata = scope;
string[] ret = new string[2];
try
{
string token = page.Request["token"];
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(urldata));
request.Headers.Add("Authorization", "AuthSub token=" + token);
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
XmlDocument doc = new XmlDocument();
if (response != null)
{
string account = string.Empty, name = string.Empty;
doc.Load(response.GetResponseStream());
XmlNode node = doc.SelectSingleNode("*/*[local-name()='id']");
if (node != null)
{
account = node.InnerText; //Email地址
}
node = doc.SelectSingleNode("*/*[local-name()='author']/*[local-name()='name']");
if (node != null)
{
name = node.InnerText; //姓名
}
ret[0] = account;
ret[1] = name;
return ret;
}
else return ret;
}
catch (Exception ex)
{
new MyException("GoogleLogin", ex.ToString());
return new string[] { "", "" };
}
}
}
相关文章推荐
- 谷歌google搜索打不开、谷歌gmail邮箱及相关服务无法登录的解决办法
- SQL Server中,搭建本地数据库服务,使用sa账户登录失败解决方法
- Android锁屏尝试次数太多导致需要google账户登录问题
- windows的服务中的登录身份本地系统账户、本地服务账户和网络服务账户修改
- windows的服务中的登录身份本地系统账户、本地服务账户和网络服务账户修改
- 【mobile】安卓图案解锁尝试次数过多导致 要解锁需要GOOGLE账户登录,解决方案
- 通过编程访问Google账户和服务
- 谷歌google搜索打不开、谷歌gmail邮箱及相关服务无法登录的解决办法
- windows的服务中的登录身份本地系统账户、本地服务账户和网络服务账户修改
- 关于Google多账户登录
- 谷歌google搜索打不开、谷歌gmail邮箱及相关服务无法登录的解决办法
- 谷歌google搜索打不开、谷歌gmail邮箱及相关服务无法登录的解决办法
- 谷歌google搜索打不开、谷歌gmail邮箱及相关服务无法登录的解决的方法
- 360 chrome不能登录Google账户
- windows的服务中的登录身份本地系统账户、本地服务账户和网络服务账户修改
- windows的服务中的登录身份本地系统账户、本地服务账户和网络服务账户修改
- 如何在APP中集成Google账户登录
- 慎重管理SQL Server服务的登录(启动)账户和密码
- 谷歌浏览器及谷歌其他相关服务无法登录账户问题解决办法
- Google浏览器使用代理,登录浏览器google账户时崩溃的解决方法