Cloud: Extract common oauth2 parts of Sumo and Osdu connector.

This commit is contained in:
Kristian Bendiksen
2024-07-12 13:26:39 +02:00
parent cc2d1de188
commit eda26bcc25
9 changed files with 364 additions and 398 deletions

View File

@@ -0,0 +1,78 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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
#include <QByteArray>
#include <QNetworkAccessManager>
#include <QOAuth2AuthorizationCodeFlow>
// #include <map>
//==================================================================================================
///
//==================================================================================================
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();
void setTokenDataFilePath( const QString& filePath );
QString server() const;
public slots:
void requestToken();
void accessGranted();
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 );
protected:
QString requestTokenBlocking();
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_token;
QString m_tokenDataFilePath;
};