yolobs-studio/UI/auth-oauth.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

80 lines
1.7 KiB
C++
Raw Normal View History

2019-07-27 12:47:10 +00:00
#pragma once
#include <QDialog>
#include <string>
#include <memory>
#include "auth-base.hpp"
class QCefWidget;
class OAuthLogin : public QDialog {
Q_OBJECT
QCefWidget *cefWidget = nullptr;
QString code;
bool get_token = false;
bool fail = false;
public:
OAuthLogin(QWidget *parent, const std::string &url, bool token);
~OAuthLogin();
2019-09-22 21:19:10 +00:00
inline QString GetCode() const { return code; }
inline bool LoadFail() const { return fail; }
2019-07-27 12:47:10 +00:00
virtual int exec() override;
public slots:
void urlChanged(const QString &url);
};
class OAuth : public Auth {
Q_OBJECT
public:
inline OAuth(const Def &d) : Auth(d) {}
2019-09-22 21:19:10 +00:00
typedef std::function<std::shared_ptr<Auth>(QWidget *)> login_cb;
2019-07-27 12:47:10 +00:00
typedef std::function<void()> delete_cookies_cb;
static std::shared_ptr<Auth> Login(QWidget *parent,
2019-09-22 21:19:10 +00:00
const std::string &service);
2019-07-27 12:47:10 +00:00
static void DeleteCookies(const std::string &service);
static void RegisterOAuth(const Def &d, create_cb create,
2019-09-22 21:19:10 +00:00
login_cb login,
delete_cookies_cb delete_cookies);
2019-07-27 12:47:10 +00:00
protected:
std::string refresh_token;
std::string token;
bool implicit = false;
uint64_t expire_time = 0;
int currentScopeVer = 0;
virtual void SaveInternal() override;
virtual bool LoadInternal() override;
2019-09-22 21:19:10 +00:00
virtual bool RetryLogin() = 0;
2019-07-27 12:47:10 +00:00
bool TokenExpired();
bool GetToken(const char *url, const std::string &client_id,
2019-09-22 21:19:10 +00:00
int scope_ver,
const std::string &auth_code = std::string(),
bool retry = false);
2019-07-27 12:47:10 +00:00
};
class OAuthStreamKey : public OAuth {
Q_OBJECT
protected:
std::string key_;
public:
inline OAuthStreamKey(const Def &d) : OAuth(d) {}
2019-09-22 21:19:10 +00:00
inline const std::string &key() const { return key_; }
2019-07-27 12:47:10 +00:00
virtual void OnStreamConfig() override;
};