Skip to content

Commit 446f009

Browse files
committed
added:insert session management for oauth token
1 parent 06be5ba commit 446f009

5 files changed

Lines changed: 73 additions & 5 deletions

File tree

‎XEngine_Source/AuthorizeModule_Configure/Config_Define.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ typedef struct
161161
bool bSwitchBanned; //黑名单
162162
bool bSwitchTokenLogin; //TOKEN开关
163163
bool bSwitchHCLogin; //硬件码登录
164+
bool bSwitchOAuth; //是否启用OAuth
164165
bool bSwitchHWBind; //硬件码绑定
165166
}XENGINE_FUNCTIONSWITCH;
166167
//////////////////////////////////////////////////////////////////////////

‎XEngine_Source/AuthorizeModule_Configure/ModuleConfigure_Json/ModuleConfigure_Json.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_Switch(LPCXSTR lpszConfigFile,
376376
pSt_ServerConfig->bSwitchBanned = st_JsonRoot["bSwitchBanned"].asBool();
377377
pSt_ServerConfig->bSwitchTokenLogin = st_JsonRoot["bSwitchTokenLogin"].asBool();
378378
pSt_ServerConfig->bSwitchHCLogin = st_JsonRoot["bSwitchHCLogin"].asBool();
379+
pSt_ServerConfig->bSwitchOAuth = st_JsonRoot["bSwitchOAuth"].asBool();
379380
pSt_ServerConfig->bSwitchHWBind = st_JsonRoot["bSwitchHWBind"].asBool();
380381
return true;
381382
}

‎XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_OAuth.cpp‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ bool XEngine_AuthorizeHTTP_OAuth(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, LP
6868
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,请求创建OAuth的TOKEN失败,内部错误:%lX"), lpszClientAddr, DBModule_GetLastError());
6969
return false;
7070
}
71+
72+
AUTHREG_USERTABLE st_UserTable = {};
73+
if (0 == st_AuthConfig.st_XSql.nDBType)
74+
{
75+
DBModule_SQLite_UserQuery(st_OAuthInfo.tszUserName, &st_UserTable);
76+
}
77+
else
78+
{
79+
DBModule_SQLite_UserQuery(st_OAuthInfo.tszUserName, &st_UserTable);
80+
}
81+
Session_Token_InsertStr(st_OAuthInfo.tszUserName, &st_UserTable.st_UserInfo, st_OAuthInfo.nExpirationTime);
82+
7183
Protocol_Packet_HttpOAuth2(tszSDBuffer, &nSDLen, &st_OAuthInfo);
7284
XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP);
7385
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,请求创建OAuth Token:%s 成功"), lpszClientAddr, st_OAuthInfo.tszTokenStr);

‎XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_Task.cpp‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,13 @@ void XCALLBACK XEngine_TaskEvent_Token(LPCXSTR lpszTokenStr, int nTimeout, int n
8686
}
8787
}
8888

89-
if (bRemove)
89+
AUTHREG_OAUTHINFO st_OAuthInfo = {};
90+
_tcsxcpy(st_OAuthInfo.tszTokenStr, lpszTokenStr);
91+
bool bRet = DBModule_SQLite_OAuthDelete(&st_OAuthInfo);
92+
93+
if (bRemove || bRet)
9094
{
9195
Session_Token_DeleteStr(lpszTokenStr);
92-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Token:%s,用户名:%s,已经超时,权限级别:%d,被移除服务器"), lpszTokenStr, st_UserInfo.tszUserName, st_UserInfo.nUserLevel);
96+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Token:%s,用户名:%s,已经超时,权限级别:%d,被移除服务器,移除类型:%s"), lpszTokenStr, st_UserInfo.tszUserName, st_UserInfo.nUserLevel, bRet ? "普通" : "OAuth");
9397
}
9498
}

‎XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/XEngine_AuthorizeService.cpp‎

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,17 @@ int main(int argc, char** argv)
160160
#endif
161161
bIsRun = true;
162162
int nRet = -1;
163-
HELPCOMPONENTS_XLOG_CONFIGURE st_XLogConfig;
163+
int nListOAuth = 0;
164+
AUTHREG_OAUTHINFO** ppSt_OAuthInfo;
164165
THREADPOOL_PARAMENT** ppSt_ListTCPThread;
165166
THREADPOOL_PARAMENT** ppSt_ListWSThread;
166167
THREADPOOL_PARAMENT** ppSt_ListHttpThread;
167168
THREADPOOL_PARAMENT** ppSt_ListMQTTParam;
169+
HELPCOMPONENTS_XLOG_CONFIGURE st_XLogConfig = {};
168170

169171
LPCXSTR lpszHTTPMime = _X("./XEngine_Config/HttpMime.types");
170172
LPCXSTR lpszHTTPCode = _X("./XEngine_Config/HttpCode.types");
171173

172-
memset(&st_XLogConfig, '\0', sizeof(HELPCOMPONENTS_XLOG_CONFIGURE));
173174
memset(&st_AuthConfig, '\0', sizeof(XENGINE_SERVICECONFIG));
174175
memset(&st_FunSwitch, '\0', sizeof(XENGINE_FUNCTIONSWITCH));
175176

@@ -463,6 +464,53 @@ int main(int argc, char** argv)
463464
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,加密传输设置为关闭,采用明文传输"));
464465
}
465466

467+
if (0 == st_AuthConfig.st_XSql.nDBType)
468+
{
469+
DBModule_SQLite_OAuthList(&ppSt_OAuthInfo, &nListOAuth);
470+
}
471+
else
472+
{
473+
DBModule_MySQL_OAuthList(&ppSt_OAuthInfo, &nListOAuth);
474+
}
475+
for (int i = 0; i < nListOAuth; i++)
476+
{
477+
//是否过期
478+
time_t nTimeCreate = 0;
479+
XENGINE_LIBTIME st_LibTime = {};
480+
BaseLib_Time_StrToTime(ppSt_OAuthInfo[i]->tszCreateTime, &st_LibTime);
481+
BaseLib_Time_StuTimeToTTime(&st_LibTime, &nTimeCreate);
482+
483+
time_t nTimeStop = time(NULL);
484+
if ((ppSt_OAuthInfo[i]->nExpirationTime + nTimeCreate) - nTimeStop > 0)
485+
{
486+
AUTHREG_USERTABLE st_UserTable = {};
487+
if (0 == st_AuthConfig.st_XSql.nDBType)
488+
{
489+
DBModule_SQLite_UserQuery(ppSt_OAuthInfo[i]->tszUserName, &st_UserTable);
490+
}
491+
else
492+
{
493+
DBModule_SQLite_UserQuery(ppSt_OAuthInfo[i]->tszUserName, &st_UserTable);
494+
}
495+
//剩余时间
496+
int nTimeLeft = nTimeStop - (ppSt_OAuthInfo[i]->nExpirationTime + nTimeCreate);
497+
Session_Token_InsertStr(ppSt_OAuthInfo[i]->tszUserName, &st_UserTable.st_UserInfo, nTimeLeft);
498+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,用户:%s 绑定TOKEN:%s ,插入会话管理器"), st_UserTable.st_UserInfo.tszUserName, ppSt_OAuthInfo[i]->tszTokenStr);
499+
}
500+
else
501+
{
502+
if (0 == st_AuthConfig.st_XSql.nDBType)
503+
{
504+
DBModule_SQLite_OAuthDelete(ppSt_OAuthInfo[i]);
505+
}
506+
else
507+
{
508+
DBModule_MySQL_OAuthDelete(ppSt_OAuthInfo[i]);
509+
}
510+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("启动服务中,检查用户:%s 绑定TOKEN:%s 过期,删除"), ppSt_OAuthInfo[i]->tszUserName, ppSt_OAuthInfo[i]->tszTokenStr);
511+
}
512+
}
513+
466514
if (0 == _xtaccess(st_AuthConfig.st_XVerification.st_XCDKey.tszKeyFile, 0))
467515
{
468516
VERIFICATION_XAUTHKEY st_AuthLocal = {};
@@ -482,6 +530,7 @@ int main(int argc, char** argv)
482530
{
483531
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("启动服务中,授权文件验证失败,授权文件没有找到"));
484532
}
533+
485534
#ifndef _DEBUG
486535
//发送信息报告
487536
if (st_AuthConfig.st_XReport.bEnable && !bIsTest)
@@ -501,7 +550,8 @@ int main(int argc, char** argv)
501550
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("启动服务中,信息报告给API服务器没有启用"));
502551
}
503552
#endif
504-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,功能开关选项,删除功能:%d,登录功能:%d,找回密码:%d,充值功能:%d,注册功能:%d,CDKey功能:%d,公告系统:%d,动态验证:%d,多端登录:%d,临时试用:%d,黑名单功能:%d,普通TOKEN:%d,硬件码登录:%d,硬件码绑定:%d"), st_FunSwitch.bSwitchDelete, st_FunSwitch.bSwitchLogin, st_FunSwitch.bSwitchPass, st_FunSwitch.bSwitchPay, st_FunSwitch.bSwitchRegister, st_FunSwitch.bSwitchCDKey, st_FunSwitch.bSwitchNotice, st_FunSwitch.bSwitchDCode, st_FunSwitch.bSwitchMulti, st_FunSwitch.bSwitchTry, st_FunSwitch.bSwitchBanned, st_FunSwitch.bSwitchTokenLogin, st_FunSwitch.bSwitchHCLogin, st_FunSwitch.bSwitchHWBind);
553+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,功能开关选项,删除功能:%d,登录功能:%d,找回密码:%d,充值功能:%d,注册功能:%d,CDKey功能:%d,公告系统:%d,动态验证:%d,多端登录:%d,临时试用:%d,黑名单功能:%d,普通TOKEN:%d,硬件码登录:%d,OAuth登录支持:%d,硬件码绑定:%d"), st_FunSwitch.bSwitchDelete, st_FunSwitch.bSwitchLogin, st_FunSwitch.bSwitchPass, st_FunSwitch.bSwitchPay, st_FunSwitch.bSwitchRegister, st_FunSwitch.bSwitchCDKey, st_FunSwitch.bSwitchNotice, st_FunSwitch.bSwitchDCode, st_FunSwitch.bSwitchMulti, st_FunSwitch.bSwitchTry, st_FunSwitch.bSwitchBanned, st_FunSwitch.bSwitchTokenLogin, st_FunSwitch.bSwitchHCLogin, st_FunSwitch.bSwitchOAuth, st_FunSwitch.bSwitchHWBind);
554+
505555
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("所有服务成功启动,网络验证服务运行中,XEngien版本:%s%s,发行版本次数:%d,当前运行版本:%s。。。"), BaseLib_Version_XNumberStr(), BaseLib_Version_XTypeStr(), st_AuthConfig.st_XVer.pStl_ListVer->size(), st_AuthConfig.st_XVer.pStl_ListVer->front().c_str());
506556

507557
while (true)

0 commit comments

Comments
 (0)