77
This commit is contained in:
@@ -30,12 +30,12 @@ namespace BLL.APIService
|
||||
}
|
||||
public static void GetSyncUserInfo()
|
||||
{
|
||||
var token = GetUserToken(); //获取接口token
|
||||
//var token = GetUserToken(); //获取接口token
|
||||
var dic = GetDepartList(); //把本地数据库中的部门全部取出作为字典
|
||||
var dicUser = GetUserInfoByAccount(); //同上把所有用户取出来
|
||||
//string file = System.Web.HttpContext.Current.Server.MapPath("~/data.txt");
|
||||
//string result = System.IO.File.ReadAllText(file);
|
||||
string result = BLL.Common.HttpHelper.HttpPostRequest(GETHRINfOAPI, "", token);
|
||||
string file = System.Web.HttpContext.Current.Server.MapPath("~/data.txt");
|
||||
string result = System.IO.File.ReadAllText(file);
|
||||
//string result = BLL.Common.HttpHelper.HttpPostRequest(GETHRINfOAPI, "", token);
|
||||
var data = JsonHelper.DeserializeJsonToObject<ResultData<List<UserInfo>>>(result);
|
||||
List<Model.SyncDataUserLogs> logList = new List<Model.SyncDataUserLogs>();
|
||||
if (data.code == "200")
|
||||
@@ -246,7 +246,7 @@ namespace BLL.APIService
|
||||
/// <returns></returns>
|
||||
private static Dictionary<string,string> GetUserInfoByAccount()
|
||||
{
|
||||
return BLL.Funs.DB.Sys_User.Select(t => new { t.UserId, t.Account }).ToList()
|
||||
return BLL.Funs.DB.Sys_User.Where(t=>t.IsPost==true).Select(t => new { t.UserId, t.Account }).ToList()
|
||||
.ToDictionary(t => t.Account.ToLower(), t => t.UserId);
|
||||
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace BLL.Common
|
||||
const string post = "POST";
|
||||
if (string.Equals(requestType, get, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
request = CreateGetHttpWebRequest(url);
|
||||
request = CreateGetHttpWebRequest(url,token);
|
||||
}
|
||||
if (string.Equals(requestType, post, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
@@ -125,12 +125,22 @@ namespace BLL.Common
|
||||
return request;
|
||||
}
|
||||
|
||||
private static HttpWebRequest CreateGetHttpWebRequest(string url)
|
||||
private static HttpWebRequest CreateGetHttpWebRequest(string url,string token)
|
||||
{
|
||||
|
||||
var getRequest = HttpWebRequest.Create(url) as HttpWebRequest;
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
{
|
||||
getRequest.ContentType = "application/json";
|
||||
getRequest.Headers.Add("token", token);
|
||||
}
|
||||
else
|
||||
{
|
||||
getRequest.ContentType = "text/html;charset=UTF-8";
|
||||
}
|
||||
getRequest.Method = "GET";
|
||||
getRequest.Timeout = 5000;
|
||||
getRequest.ContentType = "text/html;charset=UTF-8";
|
||||
|
||||
getRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
|
||||
return getRequest;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,22 @@
|
||||
<Reference Include="ICSharpCode.SharpZipLib, Version=1.3.2.10, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SharpZipLib.1.3.2\lib\net45\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.1.1.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="Microsoft.IdentityModel.Abstractions, Version=7.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.IdentityModel.Abstractions.7.6.0\lib\net461\Microsoft.IdentityModel.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.IdentityModel.JsonWebTokens, Version=7.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.IdentityModel.JsonWebTokens.7.6.0\lib\net461\Microsoft.IdentityModel.JsonWebTokens.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.IdentityModel.Logging, Version=7.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.IdentityModel.Logging.7.6.0\lib\net461\Microsoft.IdentityModel.Logging.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.IdentityModel.Tokens, Version=7.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.IdentityModel.Tokens.7.6.0\lib\net461\Microsoft.IdentityModel.Tokens.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.JScript" />
|
||||
<Reference Include="Microsoft.ReportViewer.Common, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.1484.0\lib\net40\Microsoft.ReportViewer.Common.dll</HintPath>
|
||||
@@ -103,14 +118,43 @@
|
||||
<Reference Include="NPOI.OpenXmlFormats, Version=2.5.5.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NPOI.2.5.5\lib\net45\NPOI.OpenXmlFormats.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Data.Linq" />
|
||||
<Reference Include="System.DirectoryServices" />
|
||||
<Reference Include="System.DirectoryServices.Protocols" />
|
||||
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=7.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.IdentityModel.Tokens.Jwt.7.6.0\lib\net461\System.IdentityModel.Tokens.Jwt.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.IO.Compression.FileSystem" />
|
||||
<Reference Include="System.Management" />
|
||||
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.Text.Encodings.Web, Version=4.0.5.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Text.Encodings.Web.4.7.2\lib\net461\System.Text.Encodings.Web.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Text.Json, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Text.Json.4.7.2\lib\net461\System.Text.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.DataVisualization" />
|
||||
<Reference Include="System.Web.DynamicData" />
|
||||
<Reference Include="System.Web.Entity" />
|
||||
|
||||
@@ -225,9 +225,9 @@
|
||||
})
|
||||
$("#faskloginUrl").click(function () {
|
||||
let clientId = "9379ad91-eef9-4956-a1ee-8b04bb3d42c8";
|
||||
let url = "https://login.microsoftonline.com/" + clientId + "/oauth2/v2.0/authorize";
|
||||
let url = "https://login.microsoftonline.com/ecaa386b-c8df-4ce0-ad01-740cbdb5ba55/oauth2/v2.0/authorize";
|
||||
let response_type = "code";
|
||||
let redirect_url = encodeURIComponent("http://localhost:6166/ssocallback.aspx");
|
||||
let redirect_url = encodeURIComponent("https://fcl-test.basf-ypc.net.cn/ssocallback.aspx");
|
||||
let scope = "openid profile";
|
||||
let response_mode = "query";
|
||||
let state = "state123";
|
||||
|
||||
@@ -1,9 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Bcl.AsyncInterfaces" version="1.1.0" targetFramework="net461" />
|
||||
<package id="Microsoft.IdentityModel.Abstractions" version="7.6.0" targetFramework="net461" />
|
||||
<package id="Microsoft.IdentityModel.JsonWebTokens" version="7.6.0" targetFramework="net461" />
|
||||
<package id="Microsoft.IdentityModel.Logging" version="7.6.0" targetFramework="net461" />
|
||||
<package id="Microsoft.IdentityModel.Tokens" version="7.6.0" targetFramework="net461" />
|
||||
<package id="Microsoft.ReportingServices.ReportViewerControl.WebForms" version="150.1484.0" targetFramework="net461" />
|
||||
<package id="Microsoft.SqlServer.Types" version="14.0.1016.290" targetFramework="net40" />
|
||||
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net461" />
|
||||
<package id="NPOI" version="2.5.5" targetFramework="net461" />
|
||||
<package id="Portable.BouncyCastle" version="1.8.9" targetFramework="net461" />
|
||||
<package id="SharpZipLib" version="1.3.2" targetFramework="net461" />
|
||||
<package id="System.Buffers" version="4.5.1" targetFramework="net461" />
|
||||
<package id="System.IdentityModel.Tokens.Jwt" version="7.6.0" targetFramework="net461" />
|
||||
<package id="System.Memory" version="4.5.5" targetFramework="net461" />
|
||||
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net461" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.7.1" targetFramework="net461" />
|
||||
<package id="System.Text.Encodings.Web" version="4.7.2" targetFramework="net461" />
|
||||
<package id="System.Text.Json" version="4.7.2" targetFramework="net461" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net461" />
|
||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />
|
||||
</packages>
|
||||
@@ -3,6 +3,7 @@ using BLL.Common;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
@@ -22,14 +23,14 @@ namespace FineUIPro.Web
|
||||
Response.Redirect("~/login.aspx");
|
||||
return;
|
||||
}
|
||||
var token= GetAccessToken(this.code);
|
||||
var token = GetAccessToken(this.code);
|
||||
var userInfo = getUserInfo(token);
|
||||
if (userInfo == null)
|
||||
{
|
||||
Response.Redirect("~/login.aspx");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Response.Redirect("~/index.aspx");
|
||||
}
|
||||
|
||||
@@ -40,7 +41,7 @@ namespace FineUIPro.Web
|
||||
string grant_type = "authorization_code";
|
||||
string redirect_url = "https://fcl-test.basf-ypc.net.cn/ssocallback.aspx";
|
||||
string scope = "profile openid";
|
||||
string baseUrl = $"https://login.microsoftonline.com/{clientId}/oauth2/v2.0/token";
|
||||
string baseUrl = $"https://login.microsoftonline.com/ecaa386b-c8df-4ce0-ad01-740cbdb5ba55/oauth2/v2.0/token";
|
||||
|
||||
try
|
||||
{
|
||||
@@ -62,23 +63,35 @@ namespace FineUIPro.Web
|
||||
}
|
||||
|
||||
|
||||
private UserTokenModel getUserInfo(AccessTokenModel token)
|
||||
private Model.Sys_User getUserInfo(AccessTokenModel token)
|
||||
{
|
||||
string baseUrl = "https://graph.microsoft.com/oidc/userinfo";
|
||||
|
||||
try
|
||||
{
|
||||
var result = HttpHelper.HttpGetRequest(baseUrl, token.access_token);
|
||||
BLL.ErrLogInfo.WriteLog($"获取用户信息:{result}");
|
||||
if (result.IndexOf("sub") > -1)
|
||||
var handler = new JwtSecurityTokenHandler();
|
||||
var jwtToken = handler.ReadJwtToken(token.id_token);
|
||||
string username = string.Empty;
|
||||
var result = jwtToken.Claims.Where(t => t.Type == "cn").FirstOrDefault();
|
||||
if (result != null)
|
||||
{
|
||||
var info = JsonConvert.DeserializeObject<UserTokenModel>(result);
|
||||
//写入session信息
|
||||
|
||||
//写入cookie信息
|
||||
|
||||
return info;
|
||||
BLL.ErrLogInfo.WriteLog("cn="+result?.Value);
|
||||
username = result?.Value;
|
||||
}
|
||||
|
||||
else{
|
||||
username = jwtToken.Claims.Where(t => t.Type == "preferred_username").FirstOrDefault()?.Value;
|
||||
BLL.ErrLogInfo.WriteLog("username=" + username);
|
||||
if (!string.IsNullOrEmpty(username))
|
||||
{
|
||||
username = username.Split('@')[0];
|
||||
}
|
||||
}
|
||||
var info = Funs.DB.Sys_User.Where(t => t.Account == username && t.IsPost == true).FirstOrDefault();
|
||||
if (info != null)
|
||||
{
|
||||
Session[SessionName.CurrUser] = info;
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -90,18 +103,4 @@ namespace FineUIPro.Web
|
||||
|
||||
}
|
||||
|
||||
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; }
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user