-
Notifications
You must be signed in to change notification settings - Fork 18
/
jwt.html
247 lines (225 loc) · 10 KB
/
jwt.html
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<script type="text/javascript">
RED.nodes.registerType('jwt sign',{
category: "function",
icon: "hash.png",
color: "#a6bbcf",
inputs: 1,
outputs: 1,
defaults: {
name: { value: "" },
alg: { value: "HS256" },
exp: { value: 3600, validation: RED.validators.number() },
jwkurl: { value: "" },
jwkkid: { value: "" },
secret: { value: "" },
key: { value: "" },
signvar: { value: "payload",required:true },
storetoken: { value: "payload" }
},
label: function() {
return this.name || "JWT Sign"
}
});
</script>
<script type="text/x-red" data-template-name="jwt sign">
<input type="password" style="width: 0;height: 0; visibility: hidden;position:absolute;left:0;top:0;"/>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-alg"><i class="fa fa-unlock"></i> Algorithm:</label>
<select id="node-input-alg">
<option value="HS256" selected>HS256</option>
<option value="HS384">HS384</option>
<option value="HS512">HS512</option>
<option value="RS256">RS256</option>
<option value="RS384">RS384</option>
<option value="RS512">RS512</option>
<option value="ES256">ES256</option>
<option value="ES384">ES384</option>
<option value="ES512">ES512</option>
</select>
</div>
<div class="form-row">
<label for="node-input-exp"><i class="fa fa-lock"></i> Expiration</label>
<input type="text" id="node-input-exp" placeholder="Expiration in seconds">
</div>
<div class="form-row">
<label for="node-input-jwkurl"><i class="fa fa-lock"></i> JWK URL</label>
<input type="text" id="node-input-jwkurl" placeholder="http://localhost:1800/jwk_uri">
</div>
<div class="form-row">
<label for="node-input-jwkkid"><i class="fa fa-lock"></i> JWK KID</label>
<input type="text" id="node-input-jwkkid" placeholder="my_key_id">
</div>
<div class="form-row">
<label for="node-input-secret"><i class="fa fa-lock"></i> Secret</label>
<input type="password" id="node-input-secret" placeholder="Secret">
</div>
<div class="form-row">
<label for="node-input-key"><i class="fa fa-file"></i> Key File</label>
<input type="text" id="node-input-key" placeholder="Key File">
</div>
<div class="form-row">
<label for="node-input-signvar"><i class="fa fa-book"></i> Sign:</label>
<select id="node-input-signvar">
<option value="payload" selected>msg.payload</option>
<option value="token">msg.token</option>
<option value="topic">msg.topic</option>
</select>
</div>
<div class="form-row">
<label for="node-input-storetoken"><i class="fa fa-book"></i> Store Token:</label>
<select id="node-input-storetoken">
<option value="payload" selected>msg.payload</option>
<option value="token">msg.token</option>
<option value="topic">msg.topic</option>
</select>
</div>
</script>
<script type="text/x-red" data-help-name="jwt sign">
<p>Sign using JWT protocol</p>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>
payload
<span class="property-type">string | object</span>
</dt>
<dd> the payload of the message to sign. </dd>
</dl>
<h3>Outputs</h3>
<dl class="message-properties">
<dt>
token
<span class="property-type">string</span>
</dt>
<dd>generated JWT</dd>
</dl>
<h3>Details</h3>
<p>Location of signing payload and resulting token may be configured to use other message properties</p>
<p>If defined, the <code>JWK URL</code> will be used instead of a secret/key file for signing. The <code>JWK KID</code> setting will be used to select the apropriate key from the JWK key set</p>
<p>Algorithms RS256, RS384, RS512 use a PEM encoded private key file loaded from the <code>Key File</code> property, or string containing the key from <code>NODE_RED_NODE_JWT_PRIVATE_KEY</code> environment variable.</p>
<p>Algorithms HS256, HS384, HS512 use the <code>secret</code> property or the <code>NODE_RED_NODE_JWT_SECRET</code> environment variable.</p>
<h3>References</h3>
<ul>
<li><a href="https://github.com/auth0/node-jsonwebtoken">node-jsonwebtoken</a> - documentation for JWT library.</li>
</ul>
</script>
<script type="text/javascript">
RED.nodes.registerType('jwt verify',{
category: "function",
icon: "hash.png",
color: "#a6bbcf",
inputs: 1,
outputs: 1,
defaults: {
name: { value: "" },
alg: { value: ["HS256"] },
jwkurl: { value: "" },
secret: { value: "" },
key: { value: "" },
signvar: { value: "payload" },
storetoken: { value: "payload" }
},
label: function() {
return this.name || "JWT verify"
}
});
</script>
<script type="text/x-red" data-template-name="jwt verify">
<input type="password" style="width: 0;height: 0; visibility: hidden;position:absolute;left:0;top:0;"/>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-alg"><i class="fa fa-unlock"></i> Algorithm:</label>
<select id="node-input-alg" multiple>
<option value="HS256" selected>HS256</option>
<option value="HS384">HS384</option>
<option value="HS512">HS512</option>
<option value="RS256">RS256</option>
<option value="RS384">RS384</option>
<option value="RS512">RS512</option>
<option value="ES256">ES256</option>
<option value="ES384">ES384</option>
<option value="ES512">ES512</option>
</select>
</div>
<div class="form-row">
<label for="node-input-jwkurl"><i class="fa fa-lock"></i> JWK URL</label>
<input type="text" id="node-input-jwkurl" placeholder="http://localhost:1800/jwk_uri">
</div>
<div class="form-row">
<label for="node-input-secret"><i class="fa fa-lock"></i> Secret</label>
<input type="password" id="node-input-secret" placeholder="Secret">
</div>
<div class="form-row">
<label for="node-input-key"><i class="fa fa-file"></i> Key File</label>
<input type="text" id="node-input-key" placeholder="Key File">
</div>
<div class="form-row">
<label for="node-input-signvar"><i class="fa fa-book"></i> Verify:</label>
<select id="node-input-signvar">
<option value="payload" selected>msg.payload</option>
<option value="token">msg.token</option>
<option value="topic">msg.topic</option>
<option value="bearer">Auth Bearer and Access Token Param(HTTP)</option>
</select>
</div>
<div class="form-row">
<label for="node-input-storetoken"><i class="fa fa-book"></i> Store Token:</label>
<select id="node-input-storetoken">
<option value="payload" selected>msg.payload</option>
<option value="token">msg.token</option>
<option value="topic">msg.topic</option>
</select>
</div>
</script>
<script type="text/x-red" data-help-name="jwt verify">
<p>Verify JWT signature JWT</p>
<p>Verify and store result on msg.payload, topic or token.</p>
<p>Second output receive error responses from JWT lib.</p>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>
token
<span class="property-type">string</span>
</dt>
<dd> the token of the message to verify. </dd>
</dl>
<h3>Outputs</h3>
<ol class="node-ports">
<li>Standard output
<dl class="message-properties">
<dt>
topic
<span class="property-type">string</span>
</dt>
<dd>decoded payload</dd>
</dl>
</li>
<li>Standard error
<dl class="message-properties">
<dt>
payload
<span class="property-type">string</span>
</dt>
<dd>error response from JWT lib</dd>
</dl>
</li>
</ol>
<h3>Details</h3>
<p>Location of verify token and decoded payload may be configured to use other message properties</p>
<p>If defined, the <code>JWK URL</code> will be used instead of a secret/key file for validation. The <code>kid</code> of the input token will be used to select the apropriate key from the JWK key set</p>
<p>Algorithms RS256, RS384, RS512, ES256, ES384, ES512 use a PEM encoded public key file loaded from the <code>Key File</code> property, or string containing the key from <code>NODE_RED_NODE_JWT_PUBLIC_KEY</code> environment variable.</p>
<p>Algorithms HS256, HS384, HS512 use the <code>secret</code> property or the <code>NODE_RED_NODE_JWT_SECRET</code> environment variable.</p>
<h3>References</h3>
<ul>
<li><a href="https://github.com/auth0/node-jsonwebtoken">node-jsonwebtoken</a> - documentation for JWT library.</li>
</ul>
<ul>
<li><a href="https://www.npmjs.com/package/node-jwk">node-jwk</a> - documentation for JWK library.</li>
</ul>
</script>