2012-07-12 14:09:20 +02:00
|
|
|
#ifndef OAUTHENTICATOR_H
|
|
|
|
#define OAUTHENTICATOR_H
|
|
|
|
|
2012-08-17 14:44:28 +02:00
|
|
|
#include <QDateTime>
|
2012-07-12 14:09:20 +02:00
|
|
|
#include <QObject>
|
|
|
|
#include <QTcpServer>
|
|
|
|
|
|
|
|
#include "core/network.h"
|
|
|
|
|
|
|
|
class QTcpSocket;
|
|
|
|
|
|
|
|
class OAuthenticator : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit OAuthenticator(QObject* parent = 0);
|
|
|
|
void StartAuthorisation();
|
2012-07-26 16:55:59 +02:00
|
|
|
void RefreshAuthorisation(const QString& refresh_token);
|
2012-07-12 14:09:20 +02:00
|
|
|
|
2012-07-26 16:55:59 +02:00
|
|
|
// Token to use now.
|
2012-07-28 18:18:03 +02:00
|
|
|
const QString& access_token() const { return access_token_; }
|
|
|
|
|
2012-07-26 16:55:59 +02:00
|
|
|
// Token to use to get a new access token when it expires.
|
2012-07-28 18:18:03 +02:00
|
|
|
const QString& refresh_token() const { return refresh_token_; }
|
|
|
|
|
2012-08-17 14:44:28 +02:00
|
|
|
const QDateTime& expiry_time() const { return expiry_time_; }
|
2012-08-17 22:48:45 +02:00
|
|
|
const QString& user_email() const { return user_email_; }
|
2012-08-17 14:44:28 +02:00
|
|
|
|
2012-07-28 18:18:03 +02:00
|
|
|
signals:
|
|
|
|
void Finished();
|
2012-07-12 14:09:20 +02:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void NewConnection();
|
|
|
|
void RedirectArrived(QTcpSocket* socket, QByteArray buffer);
|
|
|
|
void FetchAccessTokenFinished(QNetworkReply* reply);
|
2012-07-26 16:55:59 +02:00
|
|
|
void RefreshAccessTokenFinished(QNetworkReply* reply);
|
2012-08-17 22:48:45 +02:00
|
|
|
void FetchUserInfoFinished(QNetworkReply* reply);
|
2012-07-12 14:09:20 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
QByteArray ParseHttpRequest(const QByteArray& request) const;
|
|
|
|
void RequestAccessToken(const QByteArray& code, quint16 port);
|
2012-08-17 14:44:28 +02:00
|
|
|
void SetExpiryTime(int expires_in_seconds);
|
2012-07-12 14:09:20 +02:00
|
|
|
|
|
|
|
QTcpServer server_;
|
|
|
|
NetworkAccessManager network_;
|
|
|
|
|
|
|
|
QString access_token_;
|
|
|
|
QString refresh_token_;
|
2012-08-17 14:44:28 +02:00
|
|
|
QDateTime expiry_time_;
|
2012-08-17 22:48:45 +02:00
|
|
|
QString user_email_;
|
2012-07-12 14:09:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|