diff --git a/src/AuthService.cpp b/src/AuthService.cpp index 16e6a8c..b0fe6a6 100644 --- a/src/AuthService.cpp +++ b/src/AuthService.cpp @@ -68,16 +68,21 @@ namespace OpenWifi { } if(!CallToken.empty()) { - if(StorageService()->IsTokenRevoked(CallToken)) - return false; auto Client = UserCache_.get(CallToken); if( Client.isNull() ) { std::cout << "Fetching token from disk and updating cache: " << CallToken << " >" <<__LINE__<< std::endl; - if(StorageService()->GetToken(CallToken,UInfo)) { + SecurityObjects::UserInfoAndPolicy UInfo2; + uint64_t RevocationDate=0; + if(StorageService()->GetToken(CallToken,UInfo2,RevocationDate)) { + std::cout << "Fetching token from disk and updating cache: " << CallToken << " >" <<__LINE__<< std::endl; + if(RevocationDate!=0) + return false; Expired = (Client->webtoken.created_ + Client->webtoken.expires_in_) < time(nullptr); + std::cout << "Fetching token from disk and updating cache: " << CallToken << " >" <<__LINE__<< std::endl; if(StorageService()->GetUserById(UInfo.userinfo.Id,UInfo.userinfo)) { std::cout << "Fetching token from disk and updating cache: " << CallToken << " >" <<__LINE__<< std::endl; - UserCache_.update(UInfo.webtoken.access_token_, UInfo); + UInfo.webtoken = UInfo2.webtoken; + UserCache_.update(CallToken, UInfo); SessionToken = CallToken; return true; } @@ -376,7 +381,10 @@ namespace OpenWifi { // get the token from disk... SecurityObjects::UserInfoAndPolicy UInfo; - if(StorageService()->GetToken(TToken, UInfo)) { + uint64_t RevocationDate=0; + if(StorageService()->GetToken(TToken, UInfo, RevocationDate)) { + if(RevocationDate!=0) + return false; Expired = (UInfo.webtoken.created_ + UInfo.webtoken.expires_in_) < std::time(nullptr); std::cout << "Fetching token from disk and updating cache: " << __LINE__<< std::endl; if(StorageService()->GetUserById(UInfo.userinfo.Id,UInfo.userinfo)) { diff --git a/src/StorageService.h b/src/StorageService.h index 2d04c53..83151e1 100644 --- a/src/StorageService.h +++ b/src/StorageService.h @@ -117,7 +117,7 @@ namespace OpenWifi { bool IsTokenRevoked( std::string & Token ); bool CleanExpiredTokens(); bool RevokeAllTokens( std::string & UserName ); - bool GetToken(std::string &Token, SecurityObjects::UserInfoAndPolicy &UInfo); + bool GetToken(std::string &Token, SecurityObjects::UserInfoAndPolicy &UInfo, uint64_t &RevocationDate); /* * All ActionLinks functions diff --git a/src/storage/storage_tokens.cpp b/src/storage/storage_tokens.cpp index 77072f5..251ad46 100644 --- a/src/storage/storage_tokens.cpp +++ b/src/storage/storage_tokens.cpp @@ -42,14 +42,13 @@ namespace OpenWifi { return false; } - bool Storage::GetToken(std::string &Token, SecurityObjects::UserInfoAndPolicy &UInfo) { + bool Storage::GetToken(std::string &Token, SecurityObjects::UserInfoAndPolicy &UInfo, uint64_t &RevocationDate) { try { Poco::Data::Session Sess = Pool_->get(); Poco::Data::Statement Select(Sess); - uint32_t RevocationDate = 0 ; - + RevocationDate = 0 ; std::string St2{"SELECT " + AllTokensValuesForSelect + " From Tokens WHERE Token=?"}; Select << ConvertParams(St2), Poco::Data::Keywords::into(UInfo.webtoken.access_token_),