|
@@ -207,109 +207,125 @@ namespace TEAMModelOS.Controllers.Third
|
|
|
[AllowAnonymous]
|
|
|
public async Task<IActionResult> Sso([FromQuery] ScSSO sso,string path)
|
|
|
{
|
|
|
- var HostName = HttpContext.GetHostName();
|
|
|
+ var HostName = HttpContext.GetHostName();
|
|
|
if (path.Equals("sc"))
|
|
|
{
|
|
|
path = $"scpjx";
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
path = $"sc{path}";
|
|
|
}
|
|
|
+
|
|
|
//var rurl = new StringBuilder($"https://{_option.HostName}/sso");
|
|
|
var rurl = new StringBuilder($"https://{HostName}/sso");
|
|
|
- string parmas = $"Pxid={sso.Pxid}&Webid={sso.Webid}&tid={sso.tid}&time={sso.time}";
|
|
|
- if (Md5Hash.GetMd5String(parmas).Equals($"{sso.Encrypt}"))
|
|
|
- {
|
|
|
- //四川研训平台跳转隐式登录/或者绑定IES平台接入规范
|
|
|
+ try {
|
|
|
|
|
|
- long ssotime = long.Parse($"{sso.time}");
|
|
|
- long nowtime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
|
|
- if (nowtime - ssotime > 60 * 10)//10分钟有效期
|
|
|
+ string parmas = $"Pxid={sso.Pxid}&Webid={sso.Webid}&tid={sso.tid}&time={sso.time}";
|
|
|
+ if (Md5Hash.GetMd5String(parmas).Equals($"{sso.Encrypt}"))
|
|
|
{
|
|
|
- // return Ok(new { status = 2, msg = "登录超时!" });
|
|
|
+ //四川研训平台跳转隐式登录/或者绑定IES平台接入规范
|
|
|
+
|
|
|
+ long ssotime = long.Parse($"{sso.time}");
|
|
|
+ long nowtime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
|
|
+ if (nowtime - ssotime > 60 * 10)//10分钟有效期
|
|
|
+ {
|
|
|
+ // return Ok(new { status = 2, msg = "登录超时!" });
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return Redirect(rurl.Append($"?status=1").ToString());
|
|
|
- }
|
|
|
- string setsql = $"select value(c) from c where contains(c.accessConfig,'{path}') && contains(c.accessConfig,'scsyxpt') ";
|
|
|
- AreaSetting setting = null;
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AreaSetting>(queryText: setsql,
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AreaSetting") }))
|
|
|
- {
|
|
|
- setting = item;
|
|
|
- break;
|
|
|
- }
|
|
|
- if (setting != null && string.IsNullOrEmpty(setting.accessConfig)) {
|
|
|
- return Redirect(rurl.Append($"?status=1").ToString());
|
|
|
- }
|
|
|
- //string accessConfig = "{\"homeworkType\":[\"pdf\"],\"submitType\":[\"pdf\",\"mp4\"],\"path\":\"scpjx\",\"config\":\"scsyxpt\",\"passKey\":\"VgEQfEjwzfvFn8my\",\"trainComID\":\"2065\",\"privateKey\":\"4DB15444DEEDBB28B718ACB09217B5FC\",\"url\":\"http://testscts.scedu.com.cn/webservice/EduService.asmx/RequestService\"}";
|
|
|
- string accessConfig = setting.accessConfig;
|
|
|
- Dictionary<string, object> dict = new Dictionary<string, object> { { "accessConfig", accessConfig }, { "pxid",sso.Pxid },{ "tid",sso.tid} };
|
|
|
- (int status,string json ) =await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetSingleTeacherByProject");
|
|
|
- if (status == 200) {
|
|
|
- ScTeacher scTeacher= json.ToObject<ScTeacher>( new JsonSerializerOptions { PropertyNameCaseInsensitive = false });
|
|
|
- if (scTeacher != null && scTeacher.PXID.Equals(sso.Pxid) && scTeacher.TID.Equals(sso.tid)) {
|
|
|
-
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Redirect(rurl.Append($"?status=1").ToString());
|
|
|
}
|
|
|
- }
|
|
|
- Teacher teacher = null;
|
|
|
- //四川研训平台跳转隐式登录/或者绑定IES平台接入规范
|
|
|
- //string sql = $"SELECT distinct value(c) FROM c join A1 in c.binds where A1.pxid='{sso.Pxid}' and A1.webid='{sso.Webid}' and A1.tid='{sso.tid}'";
|
|
|
- string sql = $"SELECT distinct value(c) FROM c join A1 in c.binds where A1.source='{sso.Webid}' and A1.userid='{sso.tid}'";
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(queryText: sql,
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
|
|
|
- {
|
|
|
- teacher = item;
|
|
|
- break;
|
|
|
- }
|
|
|
- if (teacher == null)
|
|
|
- {
|
|
|
- return Redirect(rurl.Append($"?status=4¶m={sso.ToJsonString()}&type={type}&bindurl=sc/bind").ToString());
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
|
|
|
- var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
- var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
- var location = _option.Location;
|
|
|
- (int code, string content) = await _accountHttpService.Implicit(clientID, clientSecret, location, $"{url}/oauth2/implicit",
|
|
|
- new Dictionary<string, string>()
|
|
|
+ string setsql = $"select value(c) from c where contains(c.accessConfig,'{path}') and contains(c.accessConfig,'scsyxpt') ";
|
|
|
+ AreaSetting setting = null;
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AreaSetting>(queryText: setsql,
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AreaSetting") }))
|
|
|
+ {
|
|
|
+ setting = item;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (setting != null && string.IsNullOrEmpty(setting.accessConfig))
|
|
|
+ {
|
|
|
+ return Redirect(rurl.Append($"?status=1").ToString());
|
|
|
+ }
|
|
|
+ //string accessConfig = "{\"homeworkType\":[\"pdf\"],\"submitType\":[\"pdf\",\"mp4\"],\"path\":\"scpjx\",\"config\":\"scsyxpt\",\"passKey\":\"VgEQfEjwzfvFn8my\",\"trainComID\":\"2065\",\"privateKey\":\"4DB15444DEEDBB28B718ACB09217B5FC\",\"url\":\"http://testscts.scedu.com.cn/webservice/EduService.asmx/RequestService\"}";
|
|
|
+ string accessConfig = setting.accessConfig;
|
|
|
+ Dictionary<string, object> dict = new Dictionary<string, object> { { "accessConfig", accessConfig }, { "pxid", sso.Pxid }, { "tid", sso.tid } };
|
|
|
+ (int status, string json) = await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetSingleTeacherByProject");
|
|
|
+ if (status == 200)
|
|
|
+ {
|
|
|
+ ScTeacher scTeacher = json.ToObject<ScTeacher>(new JsonSerializerOptions { PropertyNameCaseInsensitive = false });
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location}\n省平台教师信息:\n{scTeacher.ToJsonString()}",GroupNames.成都开发測試群組);
|
|
|
+ if (scTeacher != null && scTeacher.PXID.Equals(sso.Pxid) && scTeacher.TID.Equals(sso.tid))
|
|
|
{
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Teacher teacher = null;
|
|
|
+ //四川研训平台跳转隐式登录/或者绑定IES平台接入规范
|
|
|
+ //string sql = $"SELECT distinct value(c) FROM c join A1 in c.binds where A1.pxid='{sso.Pxid}' and A1.webid='{sso.Webid}' and A1.tid='{sso.tid}'";
|
|
|
+ string sql = $"SELECT distinct value(c) FROM c join A1 in c.binds where A1.source='{sso.Webid}' and A1.userid='{sso.tid}'";
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(queryText: sql,
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
|
|
|
+ {
|
|
|
+ teacher = item;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (teacher == null)
|
|
|
+ {
|
|
|
+ return Redirect(rurl.Append($"?status=4¶m={sso.ToJsonString()}&type={type}&bindurl=sc/bind").ToString());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
|
|
|
+ var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
+ var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
+ var location = _option.Location;
|
|
|
+ (int code, string content) = await _accountHttpService.Implicit(clientID, clientSecret, location, $"{url}/oauth2/implicit",
|
|
|
+ new Dictionary<string, string>()
|
|
|
+ {
|
|
|
{ "grant_type", "implicit" },
|
|
|
{ "client_id",clientID },
|
|
|
{ "account",teacher.id },
|
|
|
{ "nonce",Guid.NewGuid().ToString()}
|
|
|
- });
|
|
|
- TmdidImplicit implicit_token = new TmdidImplicit();
|
|
|
- if (!string.IsNullOrEmpty(content) && code==200)
|
|
|
- {
|
|
|
- implicit_token = content.ToObject<TmdidImplicit>();
|
|
|
- var bind = teacher.binds.Find(x => x.userid.Equals(sso.tid) && x.source.Equals(sso.Webid));
|
|
|
- if (bind != null) {
|
|
|
- if (bind.pxid != null)
|
|
|
+ });
|
|
|
+ TmdidImplicit implicit_token = new TmdidImplicit();
|
|
|
+ if (!string.IsNullOrEmpty(content) && code == 200)
|
|
|
+ {
|
|
|
+ implicit_token = content.ToObject<TmdidImplicit>();
|
|
|
+ var bind = teacher.binds.Find(x => x.userid.Equals(sso.tid) && x.source.Equals(sso.Webid));
|
|
|
+ if (bind != null)
|
|
|
{
|
|
|
- if (bind.pxid.Add(sso.Pxid))
|
|
|
+ if (bind.pxid != null)
|
|
|
+ {
|
|
|
+ if (bind.pxid.Add(sso.Pxid))
|
|
|
+ {
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
+ bind.pxid = new HashSet<string> { sso.Pxid };
|
|
|
await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
|
|
|
}
|
|
|
}
|
|
|
- else {
|
|
|
- bind.pxid = new HashSet<string> { sso.Pxid };
|
|
|
+ return Redirect(rurl.Append($"?status=200&id_token={implicit_token.id_token}&access_token={implicit_token.access_token}&expires_in={implicit_token.expires_in}&token_type={implicit_token.token_type}").ToString());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //绑定失效
|
|
|
+ if (teacher.binds.IsNotEmpty())
|
|
|
+ {
|
|
|
+ teacher.binds.RemoveAll(x => x.userid.Equals(sso.tid) && x.source.Equals(sso.Webid));
|
|
|
await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
|
|
|
}
|
|
|
+ return Redirect(rurl.Append($"?status=4¶m={sso.ToJsonString()}&type={type}&bindurl=sc/bind").ToString());
|
|
|
}
|
|
|
- return Redirect(rurl.Append($"?status=200&id_token={implicit_token.id_token}&access_token={implicit_token.access_token}&expires_in={implicit_token.expires_in}&token_type={implicit_token.token_type}").ToString());
|
|
|
- }
|
|
|
- else {
|
|
|
- //绑定失效
|
|
|
- if (teacher.binds.IsNotEmpty()) {
|
|
|
- teacher.binds.RemoveAll(x => x.userid.Equals(sso.tid) && x.source.Equals(sso.Webid));
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher,teacher.id,new PartitionKey(teacher.code));
|
|
|
- }
|
|
|
- return Redirect(rurl.Append($"?status=4¶m={sso.ToJsonString()}&type={type}&bindurl=sc/bind").ToString());
|
|
|
}
|
|
|
+ } catch (Exception ex) {
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location}-\n{sso.ToJsonString()} \npath:{path}\n{ex.StackTrace}\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ return Redirect(rurl.Append($"?status=1").ToString());
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|