초기커밋

This commit is contained in:
2025-05-01 07:20:41 +09:00
commit 98bb2e3c5c
2747 changed files with 646947 additions and 0 deletions

View File

@@ -0,0 +1,160 @@
using System.Text;
using System.IdentityModel.Tokens.Jwt;
using Microsoft.IdentityModel.Tokens;
using MySqlConnector;
using ServerCore; using ServerBase;
using ServerCommon;
namespace UGQApiServer.Auth;
public class WebPortalToken
{
public string AccountId { get; set; } = "";
public AccountType AccountType { get; set; }
public ulong AccessToken { get; set; }
}
public class WebPortalTokenAuth
{
readonly string _ssoAccountDb;
readonly string _webPortalTokenSecret;
public string WebPortalTokenSecret => _webPortalTokenSecret;
public WebPortalTokenAuth(IConfiguration configuration)
{
_ssoAccountDb = configuration["SSOAccount:SsoAccountDb"] ?? "";
_webPortalTokenSecret = configuration["SSOAccount:WebPortalTokenSecret"] ?? "";
}
public async Task<ServerErrorCode> mysqlAuth(WebPortalToken token)
{
// db <20>ּ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>׻<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ó<><C3B3>
if (string.IsNullOrEmpty(_ssoAccountDb) == true)
return ServerErrorCode.Success;
var result = new Result();
var err_msg = string.Empty;
var account_id = token.AccountId;
var access_tocken = token.AccessToken;
try
{
var is_found_account_id = false;
string email = string.Empty;
UInt64 read_access_token = 0;
var read_func = delegate (MySqlDataReader dataReader)
{
is_found_account_id = true;
email = dataReader.GetString("email");
read_access_token = dataReader.GetUInt64("access_token");
return ServerErrorCode.Success;
};
// 1. <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>ο<EFBFBD> AccessToken<65><6E> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>θ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DB<44><42> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD> üũ <20>Ѵ<EFBFBD>.
result = await MySqlConnectorHelper.simpleQueryExecuteForReaderAsync(
$"SELECT * FROM wallet_user WHERE id = {account_id}", read_func, _ssoAccountDb);
if (result.isFail())
{
err_msg = $"Failed to simpleQueryExecuteForReaderAsync() for SsoAccountDb !!! : AccountId:{account_id}, {result.toBasicString()}";
Log.getLogger().error(err_msg);
return result.ErrorCode;
}
if (false == is_found_account_id)
{
err_msg = $"Not found Account ID in SsoAccountDb !!! : AccountId:{account_id}";
result.setFail(ServerErrorCode.AccountIdNotFoundInSsoAccountDb, err_msg);
Log.getLogger().error(err_msg);
return result.ErrorCode;
}
if (read_access_token != access_tocken)
{
err_msg = $"Not match AccessToken in SsoAccountDb !!! : JWT:{access_tocken} == SsoAccountDb:{read_access_token} - AccountId:{account_id}, email:{email}";
result.setFail(ServerErrorCode.AccessTokenNotMatchInSsoAccountDb, err_msg);
Log.getLogger().error(err_msg);
return result.ErrorCode;
}
}
catch (Exception e)
{
err_msg = $"Failed to query SsoAccountDb !!! : Exception:{e} - AccountId:{account_id}";
result.setFail(ServerErrorCode.MySqlDbQueryException, err_msg);
Log.getLogger().error(result.toBasicString());
return result.ErrorCode;
}
return ServerErrorCode.Success;
}
public async Task<ServerErrorCode> mysqlAuth_igm(WebPortalToken token)
{
// db <20>ּ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>׻<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ó<><C3B3>
if (string.IsNullOrEmpty(_ssoAccountDb) == true)
return ServerErrorCode.Success;
var result = new Result();
var err_msg = string.Empty;
var account_id = token.AccountId;
var access_tocken = token.AccessToken;
try
{
var is_found_account_id = false;
string email = string.Empty;
UInt64 read_access_token = 0;
var read_func = delegate (MySqlDataReader dataReader)
{
is_found_account_id = true;
email = dataReader.GetString("email");
read_access_token = dataReader.GetUInt64("access_igm_token");
return ServerErrorCode.Success;
};
// 1. <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>ο<EFBFBD> AccessToken<65><6E> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>θ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DB<44><42> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD> üũ <20>Ѵ<EFBFBD>.
result = await MySqlConnectorHelper.simpleQueryExecuteForReaderAsync(
$"SELECT * FROM wallet_user WHERE id = {account_id}", read_func, _ssoAccountDb);
if (result.isFail())
{
err_msg = $"Failed to simpleQueryExecuteForReaderAsync() for SsoAccountDb !!! : AccountId:{account_id}, {result.toBasicString()}";
Log.getLogger().error(err_msg);
return result.ErrorCode;
}
if (false == is_found_account_id)
{
err_msg = $"Not found Account ID in SsoAccountDb !!! : AccountId:{account_id}";
result.setFail(ServerErrorCode.AccountIdNotFoundInSsoAccountDb, err_msg);
Log.getLogger().error(err_msg);
return result.ErrorCode;
}
if (read_access_token != access_tocken)
{
err_msg = $"Not match AccessToken in SsoAccountDb !!! : JWT:{access_tocken} == SsoAccountDb:{read_access_token} - AccountId:{account_id}, email:{email}";
result.setFail(ServerErrorCode.AccessTokenNotMatchInSsoAccountDb, err_msg);
Log.getLogger().error(err_msg);
return result.ErrorCode;
}
}
catch (Exception e)
{
err_msg = $"Failed to query SsoAccountDb !!! : Exception:{e} - AccountId:{account_id}";
result.setFail(ServerErrorCode.MySqlDbQueryException, err_msg);
Log.getLogger().error(result.toBasicString());
return result.ErrorCode;
}
return ServerErrorCode.Success;
}
}