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