auth-base.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_), error(error_)
  16. {
  17. }
  18. };
  19. public:
  20. enum class Type {
  21. None,
  22. OAuth_StreamKey,
  23. OAuth_LinkedAccount,
  24. };
  25. struct Def {
  26. std::string service;
  27. Type type;
  28. bool externalOAuth;
  29. bool usesBroadcastFlow;
  30. };
  31. typedef std::function<std::shared_ptr<Auth>()> create_cb;
  32. inline Auth(const Def &d) : def(d) {}
  33. virtual ~Auth() {}
  34. inline Type type() const { return def.type; }
  35. inline const char *service() const { return def.service.c_str(); }
  36. inline bool external() const { return def.externalOAuth; }
  37. inline bool broadcastFlow() const { return def.usesBroadcastFlow; }
  38. virtual void LoadUI() {}
  39. virtual void OnStreamConfig() {}
  40. static std::shared_ptr<Auth> Create(const std::string &service);
  41. static Type AuthType(const std::string &service);
  42. static bool External(const std::string &service);
  43. static void Load();
  44. static void Save();
  45. protected:
  46. static void RegisterAuth(const Def &d, create_cb create);
  47. private:
  48. Def def;
  49. };