mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Cloud: save expiration timestamp for access token.
Expired access tokens are ignored when reading from file.
This commit is contained in:
@@ -124,7 +124,10 @@ RiaCloudConnector::RiaCloudConnector( QObject* parent,
|
|||||||
&QOAuth2AuthorizationCodeFlow::expirationAtChanged,
|
&QOAuth2AuthorizationCodeFlow::expirationAtChanged,
|
||||||
this,
|
this,
|
||||||
[&]( const QDateTime& expiration )
|
[&]( const QDateTime& expiration )
|
||||||
{ RiaLogging::debug( QString( "Access token expiration changed: %1" ).arg( expiration.toString() ) ); } );
|
{
|
||||||
|
RiaLogging::debug( QString( "Access token expiration changed: %1" ).arg( expiration.toString() ) );
|
||||||
|
exportTokenToFile();
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ QString RiaConnectorTools::tokenDataAsJson( QOAuth2AuthorizationCodeFlow* authCo
|
|||||||
QJsonObject obj;
|
QJsonObject obj;
|
||||||
obj.insert( "token", authCodeFlow->token() );
|
obj.insert( "token", authCodeFlow->token() );
|
||||||
obj.insert( "refreshToken", authCodeFlow->refreshToken() );
|
obj.insert( "refreshToken", authCodeFlow->refreshToken() );
|
||||||
|
if ( authCodeFlow->expirationAt().isValid() )
|
||||||
|
{
|
||||||
|
obj.insert( "expiration", authCodeFlow->expirationAt().toSecsSinceEpoch() );
|
||||||
|
}
|
||||||
|
|
||||||
QJsonDocument doc( obj );
|
QJsonDocument doc( obj );
|
||||||
return doc.toJson( QJsonDocument::Indented );
|
return doc.toJson( QJsonDocument::Indented );
|
||||||
@@ -47,7 +51,16 @@ void RiaConnectorTools::initializeTokenDataFromJson( QOAuth2AuthorizationCodeFlo
|
|||||||
QJsonDocument doc = QJsonDocument::fromJson( tokenDataJson.toUtf8() );
|
QJsonDocument doc = QJsonDocument::fromJson( tokenDataJson.toUtf8() );
|
||||||
QJsonObject obj = doc.object();
|
QJsonObject obj = doc.object();
|
||||||
|
|
||||||
authCodeFlow->setToken( obj["token"].toString() );
|
if ( obj.contains( "expiration" ) && obj.contains( "token" ) )
|
||||||
|
{
|
||||||
|
quint64 secondsSinceEpoch = obj["expiration"].toVariant().toULongLong();
|
||||||
|
QDateTime expiration = QDateTime::fromSecsSinceEpoch( secondsSinceEpoch );
|
||||||
|
if ( expiration.isValid() && expiration > QDateTime::currentDateTime() )
|
||||||
|
{
|
||||||
|
authCodeFlow->setToken( obj["token"].toString() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
authCodeFlow->setRefreshToken( obj["refreshToken"].toString() );
|
authCodeFlow->setRefreshToken( obj["refreshToken"].toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user