LeechCraft  0.6.70-13729-g7046a9d2a7
Modular cross-platform feature rich live environment.
vkauthmanager.h
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Boost Software License - Version 1.0 - August 17th, 2003
6  *
7  * Permission is hereby granted, free of charge, to any person or organization
8  * obtaining a copy of the software and accompanying documentation covered by
9  * this license (the "Software") to use, reproduce, display, distribute,
10  * execute, and transmit the Software, and to prepare derivative works of the
11  * Software, and to permit third-parties to whom the Software is furnished to
12  * do so, all subject to the following:
13  *
14  * The copyright notices in the Software and this entire statement, including
15  * the above license grant, this restriction and the following disclaimer,
16  * must be included in all copies of the Software, in whole or in part, and
17  * all derivative works of the Software, unless such copies or derivative
18  * works are solely in the form of machine-executable object code generated by
19  * a source language processor.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
24  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
25  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  **********************************************************************/
29 
30 #pragma once
31 
32 #include <functional>
33 #include <variant>
34 #include <QObject>
35 #include <QDateTime>
36 #include <QUrl>
38 #include <util/sll/util.h>
39 #include <util/sll/eitherfwd.h>
40 #include "svcauthconfig.h"
41 
42 class QTimer;
43 
44 template<typename>
45 class QFuture;
46 
47 namespace LC
48 {
49 namespace Util
50 {
51 class QueueManager;
52 enum class QueuePriority;
53 
54 class CustomCookieJar;
55 
56 namespace SvcAuth
57 {
58  class UTIL_SVCAUTH_API VkAuthManager : public QObject
59  {
60  Q_OBJECT
61 
62  ICoreProxy_ptr Proxy_;
63 
64  const QString AccountHR_;
65 
66  QNetworkAccessManager * const AuthNAM_;
67  Util::CustomCookieJar * const Cookies_;
68 
69  QueueManager * const Queue_;
70 
71  QString Token_;
72  QDateTime ReceivedAt_;
73  qint32 ValidFor_ = 0;
74 
75  bool IsRequesting_ = false;
76 
77  const QString ID_;
78  QUrl URL_;
79 
80  bool IsRequestScheduled_ = false;
81  QTimer * const ScheduleTimer_;
82 
83  bool SilentMode_ = false;
84 
85  bool HasTracked_ = false;
86  public:
89 
92 
94  private:
95  QList<RequestQueue_ptr> ManagedQueues_;
96  QList<PrioRequestQueue_ptr> PrioManagedQueues_;
97  public:
98  VkAuthManager (const QString& accountName, const QString& clientId,
99  const QStringList& scope, const QByteArray& cookies,
100  ICoreProxy_ptr, QueueManager* = nullptr, QObject* = nullptr);
101 
102  bool IsAuthenticated () const;
103  bool HadAuthentication () const;
104 
105  void UpdateScope (const QStringList&);
106 
107  void GetAuthKey ();
108 
109  struct SilentMode {};
110  using AuthKeyError_t = std::variant<SilentMode>;
112 
113  [[nodiscard]] QFuture<AuthKeyResult_t> GetAuthKeyFuture ();
114 
115  [[nodiscard]] ScheduleGuard_t ManageQueue (RequestQueue_ptr);
116  [[nodiscard]] ScheduleGuard_t ManageQueue (PrioRequestQueue_ptr);
117 
118  void SetSilentMode (bool);
119  private:
120  void InvokeQueues (const QString&);
121 
122  void RequestURL (const QUrl&);
123  void RequestAuthKey ();
124  bool CheckReply (QUrl);
125  bool CheckError (const QUrl&);
126 
127  void ScheduleTrack (const QString&);
128  public slots:
129  void clearAuthData ();
130  void reauth ();
131  private slots:
132  void execScheduledRequest ();
133  void handleGotForm ();
134  void handleViewUrlChanged (const QUrl&);
135  signals:
136  void gotAuthKey (const QString&);
137  void cookiesChanged (const QByteArray&);
138  void authCanceled ();
139  void justAuthenticated ();
140  };
141 }
142 }
143 }
detail::ScopeGuard< detail::DefaultScopeGuardDeleter > DefaultScopeGuard
Definition: util.h:134
std::variant< SilentMode > AuthKeyError_t
QueuePriority
The priority of the action in the queue.
Definition: queuemanager.h:48
A simple scheduling manager for a queue of functors.
Definition: queuemanager.h:64
#define UTIL_SVCAUTH_API
Definition: svcauthconfig.h:37
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
Definition: icoreproxy.h:202
Definition: constants.h:35