This commit is contained in:
jackchenyang
2024-06-03 14:52:50 +08:00
parent 5bcbc8e9af
commit d38dc202af
7 changed files with 52 additions and 113 deletions
+46 -10
View File
@@ -21,13 +21,21 @@ namespace FineUIPro.Web
Response.Redirect("~/login.aspx");
return;
}
GetAccessToken(this.code);
var token= GetAccessToken(this.code);
var userInfo = getUserInfo(token);
if (userInfo == null)
{
Response.Redirect("~/login.aspx");
return;
}
Response.Redirect("~/index.aspx");
}
private AccessTokenModel GetAccessToken(string _code)
{
string clientId = "";
string clientSecret = "";
string clientId = "9379ad91-eef9-4956-a1ee-8b04bb3d42c8";
string clientSecret = "iLu8Q~4DRYAn~sMjvO1j.tgRERFWhILvLYRPNc9S";
string grant_type = "authorization_code";
string redirect_url = "http://localhost:6166/ssocallback.aspx";
string scope = "profile openid";
@@ -53,17 +61,45 @@ namespace FineUIPro.Web
}
private void getUserInfo(string _code)
private UserTokenModel getUserInfo(AccessTokenModel token)
{
var objData = GetAccessToken(_code);
if (objData == null)
{
//退出去login页面
return;
}
string baseUrl = "https://graph.microsoft.com/oidc/userinfo";
try
{
var result = HttpHelper.HttpGetRequest(baseUrl, token.access_token);
if (result.IndexOf("sub") > -1)
{
var info = JsonConvert.DeserializeObject<UserTokenModel>(result);
//写入session信息
//写入cookie信息
return info;
}
}
catch (Exception ex)
{
//这里报错了,写入日志
BLL.ErrLogInfo.WriteLog(ex.Message);
}
return null;
}
}
public class UserTokenModel
{
public string sub { get; set; }
public string name { get; set; }
public string family_name { get; set; }
public string given_name { get; set; }
public string picture { get; set; }
public string email { get; set; }
}
}