Files

84 lines
2.7 KiB
C++
Raw Permalink Normal View History

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024 Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
2024-07-13 11:47:32 +02:00
#include <QObject>
2024-09-06 10:46:08 +02:00
#include <QtNetworkAuth/QAbstractOAuth>
2024-07-13 11:47:32 +02:00
class QNetworkAccessManager;
class QOAuth2AuthorizationCodeFlow;
//==================================================================================================
///
//==================================================================================================
class RiaCloudConnector : public QObject
{
Q_OBJECT
public:
RiaCloudConnector( QObject* parent,
const QString& server,
const QString& authority,
const QString& scopes,
const QString& clientId,
unsigned int port );
~RiaCloudConnector() override;
QString token() const;
void importTokenFromFile();
2024-07-12 18:51:22 +02:00
void exportTokenToFile();
void setTokenDataFilePath( const QString& filePath );
// Virtual, as a derived connector may talk to a server whose address is not known when the connector
// is constructed, and can change while it is alive.
virtual QString server() const;
QString requestTokenBlocking();
void requestTokenWithCancelButton();
2025-02-14 15:47:26 +01:00
void clearTokens();
bool isGranted() const;
public slots:
void requestToken();
void requestFailed( const QAbstractOAuth::Error error );
signals:
void tokenReady( const QString& token );
private slots:
void errorReceived( const QString& error, const QString& errorDescription, const QUrl& uri );
void authorizationCallbackReceived( const QVariantMap& data );
2024-07-12 18:51:22 +02:00
void accessGranted();
protected:
static QString constructAuthUrl( const QString& authority );
static QString constructTokenUrl( const QString& authority );
QOAuth2AuthorizationCodeFlow* m_authCodeFlow;
QNetworkAccessManager* m_networkAccessManager;
const QString m_server;
const QString m_authority;
const QString m_scopes;
const QString m_clientId;
QString m_tokenDataFilePath;
};