1 /* 2 * Copyright 2023, Andrew Lindesay <apl@lindesay.co.nz>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 #ifndef ACCESS_TOKEN_H 6 #define ACCESS_TOKEN_H 7 8 9 #include <Archivable.h> 10 #include <String.h> 11 12 class BPositionIO; 13 14 /*! When a user authenticates with the HDS system, the authentication API will 15 return a JWT access token which can then be later used with other APIs. This 16 object models the token. The reason why the token is modelled like 17 this is that the access token is not an opaque string; it contains a number 18 of key-value pairs that are known as "claims". Some of the claims are used to 19 detect, for example, when the access token has expired. 20 */ 21 22 class AccessToken : public BArchivable { 23 public: 24 AccessToken(BMessage* from); 25 AccessToken(); 26 virtual ~AccessToken(); 27 28 AccessToken& operator=(const AccessToken& other); 29 bool operator==(const AccessToken& other) const; 30 bool operator!=(const AccessToken& other) const; 31 32 const BString& Token() const; 33 uint64 ExpiryTimestamp() const; 34 35 void SetToken(const BString& value); 36 void SetExpiryTimestamp(uint64 value); 37 38 bool IsValid() const; 39 bool IsValid(uint64 currentTimestamp) const; 40 41 void Clear(); 42 43 status_t Archive(BMessage* into, bool deep = true) const; 44 private: 45 BString fToken; 46 uint64 fExpiryTimestamp; 47 // milliseconds since epoc UTC 48 }; 49 50 51 #endif // ACCESS_TOKEN_H 52