auth-base.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #include <QObject>
  3. #include <functional>
  4. #include <memory>
  5. class Auth : public QObject {
  6. Q_OBJECT
  7. protected:
  8. virtual void SaveInternal() = 0;
  9. virtual bool LoadInternal() = 0;
  10. bool firstLoad = true;
  11. struct ErrorInfo {
  12. std::string message;
  13. std::string error;
  14. ErrorInfo(std::string message_, std::string error_)
  15. : message(message_),
  16. error(error_)
  17. {
  18. }
  19. };
  20. public:
  21. enum class Type {
  22. None,
  23. OAuth_StreamKey,
  24. OAuth_LinkedAccount,
  25. };
  26. struct Def {
  27. std::string service;
  28. Type type;
  29. bool externalOAuth;
  30. bool usesBroadcastFlow;
  31. };
  32. typedef std::function<std::shared_ptr<Auth>()> create_cb;
  33. inline Auth(const Def &d) : def(d) {}
  34. virtual ~Auth() {}
  35. inline Type type() const { return def.type; }
  36. inline const char *service() const { return def.service.c_str(); }
  37. inline bool external() const { return def.externalOAuth; }
  38. inline bool broadcastFlow() const { return def.usesBroadcastFlow; }
  39. virtual void LoadUI() {}
  40. virtual void OnStreamConfig() {}
  41. static std::shared_ptr<Auth> Create(const std::string &service);
  42. static Type AuthType(const std::string &service);
  43. static bool External(const std::string &service);
  44. static void Load();
  45. static void Save();
  46. protected:
  47. static void RegisterAuth(const Def &d, create_cb create);
  48. private:
  49. Def def;
  50. };