forked from sony/nmos-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjwt_validator.h
81 lines (65 loc) · 2.26 KB
/
jwt_validator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef NMOS_JWT_VALIDATOR_H
#define NMOS_JWT_VALIDATOR_H
#include <cpprest/http_msg.h>
#include "cpprest/base_uri.h"
namespace web
{
namespace json
{
class value;
}
namespace http
{
class http_request;
}
}
namespace nmos
{
namespace experimental
{
struct insufficient_scope_exception : std::runtime_error
{
insufficient_scope_exception(const std::string& message) : std::runtime_error(message) {}
};
struct no_matching_keys_exception : std::runtime_error
{
web::uri issuer;
no_matching_keys_exception(const web::uri& issuer, const std::string& message)
: std::runtime_error(message)
, issuer(issuer) {}
};
struct scope;
namespace details
{
class jwt_validator_impl;
}
// callback for JSON validating access token
typedef std::function<void(const web::json::value& payload)> token_json_validator;
class jwt_validator
{
public:
jwt_validator() {}
jwt_validator(const web::json::value& pub_keys, token_json_validator token_validation);
// is JWT validator initialised
bool is_initialized() const;
// Token JSON validation
// may throw
void json_validation(const utility::string_t& token) const;
// Basic token validation, including token schema validation and token issuer public keys validation
// may throw
void basic_validation(const utility::string_t& token) const;
// Registered claims validation
// may throw
static void registered_claims_validation(const utility::string_t& token, const web::http::method& method, const web::uri& relative_uri, const scope& scope, const utility::string_t& audience);
// Get token client Id
// may throw
static utility::string_t get_client_id(const utility::string_t& token);
// Get token issuer
// may throw
static web::uri get_token_issuer(const utility::string_t& token);
private:
std::shared_ptr<details::jwt_validator_impl> impl;
};
}
}
#endif