Fixing token revocatiopn/

This commit is contained in:
stephb9959
2021-11-13 17:01:49 -08:00
parent c204d34bf4
commit 5b96ef396f
3 changed files with 16 additions and 9 deletions

View File

@@ -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)) {

View File

@@ -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

View File

@@ -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_),