|
@@ -1,3 +1,4 @@
|
|
|
+using Microsoft.Extensions.Configuration;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Net;
|
|
@@ -26,8 +27,14 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
/// <param name="url"></param>
|
|
|
/// <param name="data"></param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<(int code ,string content)> Implicit(string clientID, string clientSecret, string location, string url,Dictionary<string,string> data)
|
|
|
+ public async Task<TmdidImplicit> Implicit( Dictionary<string,string> data,string location, IConfiguration _configuration)
|
|
|
+
|
|
|
{
|
|
|
+ var url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
|
|
|
+ url = "https://api2-rc.teammodel.cn";
|
|
|
+ url = $"{url}/oauth2/implicit";
|
|
|
+ var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
+ var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
if (location.Contains("China"))
|
|
|
{
|
|
|
location = "China";
|
|
@@ -47,15 +54,23 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
if (responseMessage.StatusCode == HttpStatusCode.OK)
|
|
|
{
|
|
|
string content=await responseMessage.Content.ReadAsStringAsync();
|
|
|
- return (200,content);
|
|
|
+ if (!string.IsNullOrEmpty(content))
|
|
|
+ {
|
|
|
+ TmdidImplicit tmdidImplicit = content.ToObject<TmdidImplicit>();
|
|
|
+ return tmdidImplicit;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
else if (responseMessage.StatusCode == HttpStatusCode.Unauthorized)
|
|
|
{
|
|
|
- return (401,null);
|
|
|
+ return null;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return (500,null);
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
@@ -67,8 +82,13 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
/// <param name="url"></param>
|
|
|
/// <param name="data"></param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<(int code, string content)> GetUserInfo(string clientID, string clientSecret, string location, string url, Dictionary<string, string> data)
|
|
|
+ public async Task<CoreUser> GetUserInfo(Dictionary<string, string> data, string location, IConfiguration _configuration)
|
|
|
{
|
|
|
+ var url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
|
|
|
+ url = "https://api2-rc.teammodel.cn";
|
|
|
+ url = $"{url}/oauth2/getuserinfo";
|
|
|
+ var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
+ var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
if (location.Contains("China"))
|
|
|
{
|
|
|
location = "China";
|
|
@@ -88,16 +108,80 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
if (responseMessage.StatusCode == HttpStatusCode.OK)
|
|
|
{
|
|
|
string content = await responseMessage.Content.ReadAsStringAsync();
|
|
|
- return (200, content);
|
|
|
+ if (!string.IsNullOrEmpty(content))
|
|
|
+ {
|
|
|
+ CoreUserInfo coreUserInfo = content.ToObject<CoreUserInfo>();
|
|
|
+ if (coreUserInfo != null)
|
|
|
+ {
|
|
|
+ bool isActivate = !string.IsNullOrWhiteSpace(coreUserInfo.password) || !string.IsNullOrWhiteSpace(coreUserInfo.passwordOld);
|
|
|
+ CoreUser coreUser = new CoreUser
|
|
|
+ {
|
|
|
+ isActivate = isActivate,
|
|
|
+ id = coreUserInfo.id,
|
|
|
+ vid = coreUserInfo.vid,
|
|
|
+ mail = coreUserInfo.mail,
|
|
|
+ mobile = coreUserInfo.mobile,
|
|
|
+ name = coreUserInfo.name,
|
|
|
+ picture = coreUserInfo.picture,
|
|
|
+ habook = coreUserInfo.habook,
|
|
|
+ wechat = coreUserInfo.wechat,
|
|
|
+ facebook = coreUserInfo.facebook,
|
|
|
+ google = coreUserInfo.google,
|
|
|
+ ding = coreUserInfo.ding,
|
|
|
+ apple = coreUserInfo.apple,
|
|
|
+ };
|
|
|
+ return coreUser;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
else if (responseMessage.StatusCode == HttpStatusCode.Unauthorized)
|
|
|
{
|
|
|
- return (401, null);
|
|
|
+ return null;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return (500, null);
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
+ public class TmdidImplicit
|
|
|
+ {
|
|
|
+ public string id_token { get; set; }
|
|
|
+ public string access_token { get; set; }
|
|
|
+ public string expires_in { get; set; }
|
|
|
+ public string token_type { get; set; }
|
|
|
+}
|
|
|
+public class CoreUser
|
|
|
+ {
|
|
|
+ public string id { get; set; }
|
|
|
+ public string vid { get; set; }
|
|
|
+ public string mail { get; set; }
|
|
|
+ public string mobile { get; set; }
|
|
|
+ public string name { get; set; }
|
|
|
+ public string picture { get; set; }
|
|
|
+ public string habook { get; set; }
|
|
|
+ public string wechat { get; set; }
|
|
|
+ public string facebook { get; set; }
|
|
|
+ public string google { get; set; }
|
|
|
+ public string ding { get; set; }
|
|
|
+ public string apple { get; set; }
|
|
|
+ public bool isActivate { get; set; }
|
|
|
+ }
|
|
|
+ public class CoreUserInfo : CoreUser
|
|
|
+ {
|
|
|
+ public string area { get; set; }
|
|
|
+ public string country { get; set; }
|
|
|
+ public string type { get; set; }
|
|
|
+ public string password { get; set; }
|
|
|
+ public string salt { get; set; }
|
|
|
+ public string passwordOld { get; set; }
|
|
|
+ public string saltOld { get; set; }
|
|
|
+ }
|
|
|
}
|