You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
2.8 KiB
99 lines
2.8 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
using Sog;
|
|
using LitJson;
|
|
|
|
namespace HttpProxy
|
|
{
|
|
public class GoogleAuth
|
|
{
|
|
private static readonly string AuthUrl = "https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=";
|
|
|
|
|
|
/// <summary>
|
|
/// 返回验证成功后,如果验证失败返回空
|
|
/// </summary>
|
|
/// <param name="accountid"></param>
|
|
/// <param name="token"></param>
|
|
/// <param name="exception">是否Facebook服务器异常</param>
|
|
/// <returns></returns>
|
|
public static bool AuthToken(string accountid, string token, out bool exception, out string userid, out string name, out string icon, out string email)
|
|
{
|
|
userid = "";
|
|
name = "";
|
|
icon = "";
|
|
email = "";
|
|
|
|
string input_token = token;
|
|
|
|
//成功,打印一下日志
|
|
TraceLog.Debug("GoogleAuth.AuthToken, start accountid {0}", accountid);
|
|
|
|
string fullUrl = AuthUrl + input_token;
|
|
|
|
string strRet = HttpUtils.HttpGet(fullUrl, out exception, null);
|
|
|
|
if (strRet == null)
|
|
{
|
|
TraceLog.Error("GoogleAuth.AuthToken, HttpGet return null query failed");
|
|
return false;
|
|
}
|
|
|
|
TraceLog.Debug("GoogleAuth.AuthToken , http return strRet {0}", strRet);
|
|
|
|
LitJson.JsonData jsonData = JsonMapper.ToObject(strRet);
|
|
|
|
LitJson.JsonData aud = jsonData["aud"];
|
|
if (aud == null)
|
|
{
|
|
TraceLog.Error("GoogleAuth.AuthToken, ret {0}, no aud", strRet);
|
|
return false;
|
|
}
|
|
|
|
if(aud.ToString() != HttpProxyServerUtils.GetServerConfig().google_aud)
|
|
{
|
|
TraceLog.Error("GoogleAuth.AuthToken, aud invalid {0}", aud.ToString());
|
|
return false;
|
|
}
|
|
|
|
LitJson.JsonData json_sub = jsonData["sub"];
|
|
|
|
if (json_sub == null)
|
|
{
|
|
TraceLog.Error("GoogleAuth.AuthToken ,no valid json_sub");
|
|
return false;
|
|
}
|
|
|
|
userid = json_sub.ToString();
|
|
|
|
LitJson.JsonData json_name = jsonData["name"];
|
|
LitJson.JsonData json_picture = jsonData["picture"];
|
|
LitJson.JsonData json_email = jsonData["email"];
|
|
|
|
if (json_name != null)
|
|
{
|
|
name = json_name.ToString();
|
|
}
|
|
|
|
if (json_picture != null)
|
|
{
|
|
icon = json_picture.ToString();
|
|
}
|
|
|
|
if(json_email != null)
|
|
{
|
|
email = json_email.ToString();
|
|
}
|
|
|
|
|
|
//成功,打印一下日志
|
|
TraceLog.Debug("GoogleAuth.AuthToken ,ret {0}, accountid {1}", strRet, accountid);
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|
|
}
|
|
|