cesium-native 0.51.0
Loading...
Searching...
No Matches
AuthenticationToken.h
1#pragma once
2
3#include "Library.h"
4
5#include <CesiumUtility/Result.h>
6
7#include <cstdint>
8#include <string>
9#include <variant>
10#include <vector>
11
13
17class CESIUMITWINCLIENT_API AuthenticationToken {
18public:
28 parse(const std::string& tokenStr);
29
36 bool isValid() const;
37
42 int64_t getExpirationTime() const { return _expires; }
43
47 const std::string& getToken() const { return _token; }
48
55 std::string getTokenHeader() const;
56
73 const std::string& token,
74 std::string&& name,
75 std::string&& userName,
76 std::vector<std::string>&& scopes,
77 int64_t notValidBefore,
78 int64_t expires);
79
92 const std::string& token,
93 std::string&& iTwinId,
94 int64_t expires)
95 : _token(token), _contents(std::move(iTwinId)), _expires(expires) {}
96
97private:
101 struct AccessTokenContents {
103 std::string name;
105 std::string userName;
107 std::vector<std::string> scopes;
109 int64_t notValidBefore;
110 };
111
119 using AuthenticationTokenContents =
120 std::variant<AccessTokenContents, std::string>;
121
122 std::string _token;
123 AuthenticationTokenContents _contents;
124 int64_t _expires;
125};
126} // namespace CesiumITwinClient
static CesiumUtility::Result< AuthenticationToken > parse(const std::string &tokenStr)
Creates a new AuthenticationToken by parsing the provided JWT authentication token.
AuthenticationToken(const std::string &token, std::string &&iTwinId, int64_t expires)
Creates a new AuthenticationToken for a share token.
AuthenticationToken(const std::string &token, std::string &&name, std::string &&userName, std::vector< std::string > &&scopes, int64_t notValidBefore, int64_t expires)
Creates a new AuthenticationToken for an access token.
const std::string & getToken() const
Returns the contained token string.
std::string getTokenHeader() const
Returns the HTTP Authorization header for this token.
bool isValid() const
Is this token currently valid?
int64_t getExpirationTime() const
Returns the number of seconds since the Unix epoch representing the time that this token expires.
Classes for interacting with the iTwin API.
STL namespace.
Holds the result of an operation. If the operation succeeds, it will provide a value....
Definition Result.h:16