Overte C++ Documentation
DomainAccountManager.h
1 //
2 // DomainAccountManager.h
3 // libraries/networking/src
4 //
5 // Created by David Rowe on 23 Jul 2020.
6 // Copyright 2020 Vircadia contributors.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_DomainAccountManager_h
13 #define hifi_DomainAccountManager_h
14 
15 #include <QtCore/QObject>
16 #include <QtCore/QUrl>
17 
18 #include <DependencyManager.h>
19 
20 
21 struct DomainAccountDetails {
22  QUrl domainURL;
23  QUrl authURL;
24  QString clientID;
25  QString username;
26  QString accessToken;
27  QString refreshToken;
28  QString authedDomainName;
29 };
30 
31 
32 class DomainAccountManager : public QObject, public Dependency {
33  Q_OBJECT
34 public:
35  DomainAccountManager();
36 
37  void setDomainURL(const QUrl& domainURL);
38  void setAuthURL(const QUrl& authURL);
39  void setClientID(const QString& clientID) { _currentAuth.clientID = clientID; }
40 
41  const QString& getUsername() { return _currentAuth.username; }
42  const QString& getAccessToken() { return _currentAuth.accessToken; }
43  const QString& getRefreshToken() { return _currentAuth.refreshToken; }
44  const QString& getAuthedDomainName() { return _currentAuth.authedDomainName; }
45 
46  bool hasLogIn();
47  bool isLoggedIn();
48 
49  Q_INVOKABLE bool checkAndSignalForAccessToken();
50 
51 public slots:
52  void requestAccessToken(const QString& username, const QString& password);
53  void requestAccessTokenFinished();
54 
55 signals:
56  void hasLogInChanged(bool hasLogIn);
57  void authRequired(const QString& domain);
58  void loginComplete();
59  void loginFailed();
60  void logoutComplete();
61  void newTokens();
62 
63 private:
64  bool hasValidAccessToken();
65  bool accessTokenIsExpired();
66  void setTokensFromJSON(const QJsonObject&, const QUrl& url);
67  void sendInterfaceAccessTokenToServer();
68 
69  DomainAccountDetails _currentAuth;
70  QHash<QUrl, DomainAccountDetails> _knownAuths; // <domainURL, DomainAccountDetails>
71 };
72 
73 #endif // hifi_DomainAccountManager_h