1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
// oauth.h.mustache
// licenseInfo.mustache
/**
* Libre Graph API
* Libre Graph is a free API for cloud collaboration inspired by the MS Graph API.
*
* The version of the OpenAPI document: v1.0.4
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/**
* Providing a Oauth2 Class and a ReplyServer for the Oauth2 authorization code flow.
*/
#ifndef OAI_OAUTH2_H
#define OAI_OAUTH2_H
#include <QObject>
#include <QtCore>
#include <QtNetwork>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QNetworkAccessManager>
#include <QtDebug>
#include <QTcpServer>
#include <QTcpSocket>
#include <QByteArray>
#include <QString>
#include <QMap>
#include <QUrl>
#include <QUrlQuery>
#include <QDateTime>
#include <time.h>
namespace OpenAPI {
class oauthToken
{
public:
oauthToken(QString token, int expiresIn, QString scope, QString tokenType) : m_token(token), m_scope(scope), m_type(tokenType){
m_validUntil = time(0) + expiresIn;
}
oauthToken(){
m_validUntil = time(0) - 1;
}
QString getToken(){return m_token;};
QString getScope(){return m_scope;};
QString getType(){return m_type;};
bool isValid(){return time(0) < m_validUntil;};
private:
QString m_token;
time_t m_validUntil;
QString m_scope;
QString m_type;
};
class ReplyServer : public QTcpServer
{
Q_OBJECT
public:
explicit ReplyServer(QObject *parent = nullptr);
void setReply(QByteArray reply){m_reply = reply;};
void run();
private:
QByteArray m_reply;
signals:
void dataReceived(QMap<QString, QString>);
public slots:
void onConnected();
void read();
void start();
void stop();
};
//Base class
class OauthBase : public QObject
{
Q_OBJECT
public:
OauthBase(QObject* parent = nullptr) : QObject(parent) {};
oauthToken getToken(QString scope);
void addToken(oauthToken token);
void removeToken(QString scope);
bool linked(){return m_linked;};
virtual void link()=0;
virtual void unlink()=0;
protected:
QMap<QString, oauthToken> m_oauthTokenMap;
QUrl m_authUrl;
QUrl m_tokenUrl;
QString m_scope, m_accessType, m_state, m_redirectUri, m_clientId, m_clientSecret;
bool m_linked;
public slots:
virtual void authenticationNeededCallback()=0;
void onFinish(QNetworkReply *rep);
signals:
void authenticationNeeded();
void tokenReceived();
};
// Authorization code flow
class OauthCode : public OauthBase
{
Q_OBJECT
public:
OauthCode(QObject *parent = nullptr);
void link() override;
void unlink() override;
void setVariables(QString authUrl, QString tokenUrl, QString scope, QString state, QString redirectUri, QString clientId, QString clientSecret, QString accessType = "");
private:
ReplyServer m_server;
public slots:
void authenticationNeededCallback() override;
void onVerificationReceived(const QMap<QString, QString> response);
};
// Implicit flow
class OauthImplicit : public OauthBase
{
Q_OBJECT
public:
OauthImplicit(QObject *parent = nullptr);
void link() override;
void unlink() override;
void setVariables(QString authUrl, QString scope, QString state, QString redirectUri, QString clientId, QString accessType = "");
private:
ReplyServer m_server;
public slots:
void authenticationNeededCallback() override;
void ImplicitTokenReceived(const QMap<QString, QString> response);
};
//client credentials flow
class OauthCredentials : public OauthBase
{
Q_OBJECT
public:
OauthCredentials(QObject *parent = nullptr);
void link() override;
void unlink() override;
void setVariables(QString tokenUrl, QString scope, QString clientId, QString clientSecret);
public slots:
void authenticationNeededCallback() override;
};
//resource owner password flow
class OauthPassword : public OauthBase
{
Q_OBJECT
public:
OauthPassword(QObject *parent = nullptr);
void link() override;
void unlink() override;
void setVariables(QString tokenUrl, QString scope, QString clientId, QString clientSecret, QString username, QString password);
private:
QString m_username, m_password;
public slots:
void authenticationNeededCallback() override;
};
} // namespace OpenAPI
#endif // OAI_OAUTH2_H
|