Overte C++ Documentation
OAuthAccessToken.h
1 //
2 // OAuthAccessToken.h
3 // libraries/networking/src
4 //
5 // Created by Stephen Birarda on 2/18/2014.
6 // Copyright 2014 High Fidelity, Inc.
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_OAuthAccessToken_h
13 #define hifi_OAuthAccessToken_h
14 
15 #include <QtCore/QObject>
16 #include <QtCore/QDateTime>
17 #include <QtCore/QJsonObject>
18 
19 class OAuthAccessToken : public QObject {
20  Q_OBJECT
21 public:
22  OAuthAccessToken();
23  OAuthAccessToken(const QJsonObject& jsonObject);
24  OAuthAccessToken(const OAuthAccessToken& otherToken);
25  OAuthAccessToken& operator=(const OAuthAccessToken& otherToken);
26 
27  QByteArray authorizationHeaderValue() const { return QString("Bearer %1").arg(token).toUtf8(); }
28 
29  bool isExpired() const { return expiryTimestamp != -1 && expiryTimestamp <= QDateTime::currentMSecsSinceEpoch(); }
30 
31  QString token;
32  QString refreshToken;
33  qlonglong expiryTimestamp;
34  QString tokenType;
35 
36  friend QDataStream& operator<<(QDataStream &out, const OAuthAccessToken& token);
37  friend QDataStream& operator>>(QDataStream &in, OAuthAccessToken& token);
38 private:
39  void swap(OAuthAccessToken& otherToken);
40 };
41 
42 #endif // hifi_OAuthAccessToken_h