10Duke Enterprise C++ SDK
Loading...
Searching...
No Matches
DynamicJWKSSignatureValidator.h
1#ifndef TENDUKE_JWK_DYNAMICJWKSVALIDATOR_H
2#define TENDUKE_JWK_DYNAMICJWKSVALIDATOR_H
3
4#include "./JWKS.h"
5#include "./JWKSDownloader.h"
6#include "./JWKSSignatureValidator.h"
7#include "../crypto/msgauthn/HashAlgorithm.h"
8#include "../time/Clock.h"
9
10#include <cstdint>
11#include <mutex>
12
13namespace tenduke { namespace jwk {
14
29{
30public:
32 static const std::int64_t DEFAULT_MIN_REFRESH_INTERVAL_S = 300;
33
47 const std::shared_ptr<tenduke::jwk::JWKS> &keySet,
48 const std::shared_ptr<const tenduke::jwk::JWKSDownloader> &jwksDownloader,
49 std::string jwksUrl,
50 const std::shared_ptr<const tenduke::time::Clock> &clock,
51 ::tenduke::crypto::HashAlgorithm validationAlgorithm = ::tenduke::crypto::HashAlgorithm::NONE,
52 std::int64_t minRefreshIntervalS = DEFAULT_MIN_REFRESH_INTERVAL_S
53 );
54
55protected:
65 std::unique_ptr<tenduke::jwk::JWK> findJWK(const std::string &keyId) const override;
66
74 std::unique_ptr<tenduke::jwk::JWK> findRotatedJWK(const tenduke::jwk::JWK &rejectedKey) const override;
75
76private:
83 bool refreshKeys() const;
84
85 const std::shared_ptr<const tenduke::jwk::JWKSDownloader> downloadJWKS;
86 const std::string jwksURL;
87 const std::shared_ptr<const tenduke::time::Clock> clock;
88 const std::int64_t minRefreshIntervalS;
89
91 mutable std::mutex refreshMutex;
93 mutable bool hasRefreshed = false;
95 mutable std::int64_t lastRefreshAt = 0;
96};
97
98}}
99
100#endif //TENDUKE_JWK_DYNAMICJWKSVALIDATOR_H
DynamicJWKSSignatureValidator(const std::shared_ptr< tenduke::jwk::JWKS > &keySet, const std::shared_ptr< const tenduke::jwk::JWKSDownloader > &jwksDownloader, std::string jwksUrl, const std::shared_ptr< const tenduke::time::Clock > &clock, ::tenduke::crypto::HashAlgorithm validationAlgorithm=::tenduke::crypto::HashAlgorithm::NONE, std::int64_t minRefreshIntervalS=DEFAULT_MIN_REFRESH_INTERVAL_S)
Constructs new instance.
Definition DynamicJWKSSignatureValidator.cpp:109
static const std::int64_t DEFAULT_MIN_REFRESH_INTERVAL_S
Default minimum interval in seconds between key set refreshes.
Definition DynamicJWKSSignatureValidator.h:32
std::unique_ptr< tenduke::jwk::JWK > findJWK(const std::string &keyId) const override
Locates the key from cache by id.
Definition DynamicJWKSSignatureValidator.cpp:21
std::unique_ptr< tenduke::jwk::JWK > findRotatedJWK(const tenduke::jwk::JWK &rejectedKey) const override
Refreshes the cache (unless refreshed within minRefreshIntervalS) and returns the only cached key usa...
Definition DynamicJWKSSignatureValidator.cpp:52
A tenduke::jwt::JWTSignatureValidator, which determines the validation key and algorithm based on the...
Definition JWKSSignatureValidator.h:30
Describes a JWK, Json Web Key.
Definition JWK.h:17
HashAlgorithm
Currently supported hash algorithms.
Definition HashAlgorithm.h:13
Support for JSON Web Keys.
Definition DynamicJWKSSignatureValidator.h:13
Root for classes, functions and globals of 10Duke C++ Client.
Definition APIRequest.h:4