forked from corona-warn-app/Swift-JWT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
334 lines (279 loc) · 25.2 KB
/
index.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<!DOCTYPE html>
<html lang="en">
<head>
<title>SwiftJWT Reference</title>
<link rel="stylesheet" type="text/css" href="css/jazzy.css" />
<link rel="stylesheet" type="text/css" href="css/highlight.css" />
<meta charset="utf-8">
<script src="js/jquery.min.js" defer></script>
<script src="js/jazzy.js" defer></script>
<script src="js/lunr.min.js" defer></script>
<script src="js/typeahead.jquery.js" defer></script>
<script src="js/jazzy.search.js" defer></script>
</head>
<body>
<a title="SwiftJWT Reference"></a>
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="index.html">
SwiftJWT 3.6.200 Docs
</a>
(100% documented)
</p>
<p class="header-col--secondary">
<form role="search" action="search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
</form>
</p>
<p class="header-col header-col--secondary">
<a class="header-link" href="https://github.com/Kitura/Swift-JWT/">
<img class="header-icon" src="img/gh.png"/>
View on GitHub
</a>
</p>
</header>
<p class="breadcrumbs">
<a class="breadcrumb" href="index.html">SwiftJWT Reference</a>
<img class="carat" src="img/carat.png" />
SwiftJWT Reference
</p>
<div class="content-wrapper">
<nav class="navigation">
<ul class="nav-groups">
<li class="nav-group-name">
<a class="nav-group-name-link" href="Classes.html">Classes</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/ClaimsMicroProfile.html">ClaimsMicroProfile</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/ClaimsOpenID.html">ClaimsOpenID</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/ClaimsStandardJWT.html">ClaimsStandardJWT</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/JWTDecoder.html">JWTDecoder</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/JWTEncoder.html">JWTEncoder</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="Protocols.html">Protocols</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/Claims.html">Claims</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="Structs.html">Structures</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/AddressClaim.html">AddressClaim</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/Header.html">Header</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/JWT.html">JWT</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/JWTError.html">JWTError</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/JWTSigner.html">JWTSigner</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/JWTVerifier.html">JWTVerifier</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/ValidateClaimsResult.html">ValidateClaimsResult</a>
</li>
</ul>
</li>
</ul>
</nav>
<article class="main-content">
<section class="section">
<div class="section-content top-matter">
<p align="center">
<a href="http://kitura.io/">
<img src="https://raw.githubusercontent.com/Kitura/Kitura/master/Sources/Kitura/resources/kitura-bird.svg?sanitize=true" height="100" alt="Kitura">
</a>
</p>
<p align="center">
<a href="https://kitura.github.io/Swift-JWT/index.html">
<img src="https://img.shields.io/badge/apidoc-SwiftJWT-1FBCE4.svg?style=flat" alt="APIDoc">
</a>
<a href="https://travis-ci.org/Kitura/Swift-JWT">
<img src="https://travis-ci.org/Kitura/Swift-JWT.svg?branch=master" alt="Build Status - Master">
</a>
<img src="https://img.shields.io/badge/os-macOS-green.svg?style=flat" alt="macOS">
<img src="https://img.shields.io/badge/os-linux-green.svg?style=flat" alt="Linux">
<img src="https://img.shields.io/badge/license-Apache2-blue.svg?style=flat" alt="Apache 2">
<a href="http://swift-at-ibm-slack.mybluemix.net/">
<img src="http://swift-at-ibm-slack.mybluemix.net/badge.svg" alt="Slack Status">
</a>
</p>
<h1 id='swiftjwt' class='heading'>SwiftJWT</h1>
<p>An implementation of <a href="https://tools.ietf.org/html/rfc7519">JSON Web Token</a> using Swift. JWTs offer a lightweight and compact format for transmitting information between parties, and the information can be verified and trusted due to JWTs being digitally signed.</p>
<p>For more information on JSON Web Tokens, their use cases and how they work, we recommend visiting <a href="https://jwt.io/introduction/">jwt.io</a>.</p>
<p><strong>Reminder:</strong> JWTs sent as JWS do <strong>not</strong> encrypt data, so never send anything sensitive or confidential in a JWT. This library does not currently support JWE.</p>
<h2 id='swift-version' class='heading'>Swift version</h2>
<p>The latest version of Swift-JWT requires <strong>Swift 4.0</strong> or later. You can download this version of the Swift binaries by following this <a href="https://swift.org/download/">link</a>. Compatibility with other Swift versions is not guaranteed.</p>
<h2 id='usage' class='heading'>Usage</h2>
<h3 id='swift-package-manager' class='heading'>Swift Package Manager</h3>
<h4 id='add-dependencies' class='heading'>Add dependencies</h4>
<p>Add the <code>Swift-JWT</code> package to the dependencies within your application’s <code>Package.swift</code> file. Substitute <code>"x.x.x"</code> with the latest <code>Swift-JWT</code> <a href="https://github.com/Kitura/Swift-JWT/releases">release</a>.</p>
<pre class="highlight swift"><code><span class="o">.</span><span class="nf">package</span><span class="p">(</span><span class="nv">url</span><span class="p">:</span> <span class="s">"https://github.com/Kitura/Swift-JWT.git"</span><span class="p">,</span> <span class="nv">from</span><span class="p">:</span> <span class="s">"x.x.x"</span><span class="p">)</span>
</code></pre>
<p>Add <code>SwiftJWT</code> to your target’s dependencies:</p>
<pre class="highlight swift"><code><span class="o">.</span><span class="nf">target</span><span class="p">(</span><span class="nv">name</span><span class="p">:</span> <span class="s">"example"</span><span class="p">,</span> <span class="nv">dependencies</span><span class="p">:</span> <span class="p">[</span><span class="s">"SwiftJWT"</span><span class="p">]),</span>
</code></pre>
<h4 id='import-package' class='heading'>Import package</h4>
<pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">SwiftJWT</span>
</code></pre>
<h3 id='cocoapods' class='heading'>Cocoapods</h3>
<p>To include <code>Swift-JWT</code> in a project using CocoaPods, add <code>SwiftJWT</code> to your Podfile:</p>
<pre class="highlight plaintext"><code>pod 'SwiftJWT'
</code></pre>
<h2 id='getting-started' class='heading'>Getting Started</h2>
<h3 id='the-jwt-model' class='heading'>The JWT model</h3>
<p>In its compact form, a JSON Web Tokens consist of three sections of Base64Url encoded JSON, separated by dots (.).<br>
These section are: Headers, Claims and the Signature.
Therefore, a JWT typically looks like the following: xxxxx.yyyyy.zzzzz</p>
<h4 id='header' class='heading'>Header</h4>
<p>The Header struct contains the fields of the JSON Web Token header as defined by <a href="https://tools.ietf.org/html/rfc7515#section-4">RFC7515</a>.<br>
The “typ” header will default to “JWT”. The “alg” header will be set to the algorithm name when you sign the JWT.<br>
The other Header fields can be set when initializing the Header or by changing them directly on the Header object.</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">myHeader</span> <span class="o">=</span> <span class="kt">Header</span><span class="p">(</span><span class="nv">kid</span><span class="p">:</span> <span class="s">"KeyID1"</span><span class="p">)</span>
</code></pre>
<h4 id='claims' class='heading'>Claims</h4>
<p>Claims are statements about an entity (typically, the user) and additional data.
The Claims are defined by creating a Swift type that conforms to the <code><a href="Protocols/Claims.html">Claims</a></code> protocol. The fields of this type represent the information that will be shared using the JWT. </p>
<p>A list of recommended claims is defined in <a href="https://tools.ietf.org/html/rfc7519#section-4.1">RFC7519</a>.</p>
<pre class="highlight swift"><code><span class="kd">struct</span> <span class="kt">MyClaims</span><span class="p">:</span> <span class="kt">Claims</span> <span class="p">{</span>
<span class="k">let</span> <span class="nv">iss</span><span class="p">:</span> <span class="kt">String</span>
<span class="k">let</span> <span class="nv">sub</span><span class="p">:</span> <span class="kt">String</span>
<span class="k">let</span> <span class="nv">exp</span><span class="p">:</span> <span class="kt">Date</span>
<span class="k">let</span> <span class="nv">admin</span><span class="p">:</span> <span class="kt">Bool</span>
<span class="p">}</span>
<span class="k">let</span> <span class="nv">myClaims</span> <span class="o">=</span> <span class="kt">MyClaims</span><span class="p">(</span><span class="nv">iss</span><span class="p">:</span> <span class="s">"Kitura"</span><span class="p">,</span> <span class="nv">sub</span><span class="p">:</span> <span class="s">"John"</span><span class="p">,</span> <span class="nv">exp</span><span class="p">:</span> <span class="kt">Date</span><span class="p">(</span><span class="nv">timeIntervalSinceNow</span><span class="p">:</span> <span class="mi">3600</span><span class="p">),</span> <span class="nv">admin</span><span class="p">:</span> <span class="kc">true</span><span class="p">)</span>
</code></pre>
<h5 id='claimsexamples' class='heading'>ClaimsExamples</h5>
<p>This library includes some example <code><a href="Protocols/Claims.html">Claims</a></code> structs as defined by their online specifications:</p>
<ul>
<li><code><a href="Classes/ClaimsStandardJWT.html">ClaimsStandardJWT</a></code> as defined in <a href="https://tools.ietf.org/html/rfc7519#section-4.1">RFC7519</a>.</li>
<li><code><a href="Classes/ClaimsMicroProfile.html">ClaimsMicroProfile</a></code> as defined <a href="http://microprofile.io/project/eclipse/microprofile-jwt-auth/spec/src/main/asciidoc/interoperability.asciidoc">here</a>.</li>
<li><code>ClaimsOpenID.swift</code> as defined <a href="https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims">here</a>.</li>
</ul>
<h4 id='jwt' class='heading'>JWT</h4>
<p>The JWT struct represents the <code><a href="Structs/Header.html">Header</a></code> and <code><a href="Protocols/Claims.html">Claims</a></code> of a JSON Web Token.<br>
You can initialize a JWT by decoding a JWT String, or by providing the JWT Header and Claims.</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">myJWT</span> <span class="o">=</span> <span class="kt">JWT</span><span class="p">(</span><span class="nv">header</span><span class="p">:</span> <span class="n">myHeader</span><span class="p">,</span> <span class="nv">claims</span><span class="p">:</span> <span class="n">myClaims</span><span class="p">)</span>
</code></pre>
<h3 id='signing-and-verifying-json-web-tokens' class='heading'>Signing and Verifying JSON web tokens</h3>
<h4 id='creating-public-and-private-keys' class='heading'>Creating public and private keys</h4>
<p>To sign and verify a JWT using an RSA algorithm, you must provide a public and private key. This could be the contents of a .key file generated via the following Terminal commands:</p>
<pre class="highlight plaintext"><code>$ ssh-keygen -t rsa -b 4096 -m PEM -f privateKey.key
# Don't add a passphrase
$ openssl rsa -in privateKey.key -pubout -outform PEM -out privateKey.key.pub
</code></pre>
<p>This will create a public and private key pair on your system, and the contents of the private key can be passed into a Swift variable using the following code:</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">privateKeyPath</span> <span class="o">=</span> <span class="kt">URL</span><span class="p">(</span><span class="nv">fileURLWithPath</span><span class="p">:</span> <span class="nf">getAbsolutePath</span><span class="p">(</span><span class="nv">relativePath</span><span class="p">:</span> <span class="s">"/path/to/privateKey.key"</span><span class="p">))</span>
<span class="k">let</span> <span class="nv">privateKey</span><span class="p">:</span> <span class="kt">Data</span> <span class="o">=</span> <span class="k">try</span> <span class="kt">Data</span><span class="p">(</span><span class="nv">contentsOf</span><span class="p">:</span> <span class="n">privateKeyPath</span><span class="p">,</span> <span class="nv">options</span><span class="p">:</span> <span class="o">.</span><span class="n">alwaysMapped</span><span class="p">)</span>
<span class="k">let</span> <span class="nv">publicKeyPath</span> <span class="o">=</span> <span class="kt">URL</span><span class="p">(</span><span class="nv">fileURLWithPath</span><span class="p">:</span> <span class="nf">getAbsolutePath</span><span class="p">(</span><span class="nv">relativePath</span><span class="p">:</span> <span class="s">"/path/to/publicKey.key"</span><span class="p">))</span>
<span class="k">let</span> <span class="nv">publicKey</span><span class="p">:</span> <span class="kt">Data</span> <span class="o">=</span> <span class="k">try</span> <span class="kt">Data</span><span class="p">(</span><span class="nv">contentsOf</span><span class="p">:</span> <span class="n">publicKeyPath</span><span class="p">,</span> <span class="nv">options</span><span class="p">:</span> <span class="o">.</span><span class="n">alwaysMapped</span><span class="p">)</span>
</code></pre>
<p>For details on creating elliptic curve public and private keys, view the <a href="https://github.com/Kitura/BlueECC">BlueECC README.txt</a>.</p>
<h4 id='sign-a-jwt-using-a-jwtsigner' class='heading'>Sign a JWT using a JWTSigner</h4>
<p>The struct JWTSigner contains the algorithms that can be used to sign a JWT.</p>
<p>Initialize a JWTSigner using the static function corresponding to the desired RSA algorithm:</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">jwtSigner</span> <span class="o">=</span> <span class="kt">JWTSigner</span><span class="o">.</span><span class="nf">rs256</span><span class="p">(</span><span class="nv">privateKey</span><span class="p">:</span> <span class="n">privateKey</span><span class="p">)</span>
</code></pre>
<p>To generate a signed JWT string, call the <code>sign</code> function on your JWT instance, passing in a JWTSigner:</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">signedJWT</span> <span class="o">=</span> <span class="k">try</span> <span class="n">myJWT</span><span class="o">.</span><span class="nf">sign</span><span class="p">(</span><span class="nv">using</span><span class="p">:</span> <span class="n">jwtSigner</span><span class="p">)</span>
</code></pre>
<p>The resulting <code>signedJWT</code> will be a <code>String</code> of the form:</p>
<pre class="highlight plaintext"><code><encoded header>.<encoded claims>.<signature>
</code></pre>
<p><strong>Note:</strong> The sign function sets the alg (algorithm) field of the header.</p>
<h4 id='verify-a-jwt-using-jwtverifier' class='heading'>Verify a JWT using JWTVerifier</h4>
<p>The struct JWTVerifier contains the algorithms that can be used to verify a JWT.</p>
<p>Initialize a JWTVerifier using the static function corresponding to the desired RSA algorithm:</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">jwtVerifier</span> <span class="o">=</span> <span class="kt">JWTVerifier</span><span class="o">.</span><span class="nf">rs256</span><span class="p">(</span><span class="nv">publicKey</span><span class="p">:</span> <span class="n">publicKey</span><span class="p">)</span>
</code></pre>
<p>To verify a signed JWT string, call the static <code>verify</code> function, passing in your JWT string and the JWTVerifier:</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">verified</span> <span class="o">=</span> <span class="kt">JWT</span><span class="o"><</span><span class="kt">MyClaims</span><span class="o">>.</span><span class="nf">verify</span><span class="p">(</span><span class="n">signedJWT</span><span class="p">,</span> <span class="nv">using</span><span class="p">:</span> <span class="n">jwtVerifier</span><span class="p">)</span>
</code></pre>
<p>The <code>verified</code> field will be a <code>bool</code> that is true if the signature is verified.</p>
<h4 id='supported-algorithms' class='heading'>Supported Algorithms</h4>
<p>The supported algorithms for signing and verifying JWTs are:</p>
<ul>
<li>RS256 - RSASSA-PKCS1-v1_5 using SHA-256</li>
<li>RS384 - RSASSA-PKCS1-v1_5 using SHA-384</li>
<li>RS512 - RSASSA-PKCS1-v1_5 using SHA-512</li>
<li>HS256 - HMAC using using SHA-256</li>
<li>HS384 - HMAC using using SHA-384</li>
<li>HS512 - HMAC using using SHA-512</li>
<li>ES256 - ECDSA using using SHA-256 and a P-256 curve</li>
<li>ES384 - ECDSA using using SHA-384 and a P-384 curve</li>
<li>ES512 - ECDSA using using SHA-512 and a P-521 curve</li>
<li>PS256 - RSA-PSS using SHA-256</li>
<li>PS384 - RSA-PSS using SHA-384</li>
<li>PS512 - RSA-PSS using SHA-512</li>
<li>none - Don’t sign or verify the JWT</li>
</ul>
<p>Note: ECDSA and RSA-PSS algorithms require a minimum Swift version of 4.1.</p>
<h3 id='validate-claims' class='heading'>Validate claims</h3>
<p>The <code>validateClaims</code> function validates the standard <code>Date</code> claims of a JWT instance.
The following claims are validated if they are present in the <code><a href="Protocols/Claims.html">Claims</a></code> object:</p>
<ul>
<li>exp (expiration date)</li>
<li>nbf (not before date)</li>
<li>iat (issued at date)</li>
</ul>
<p>The method returns <code><a href="Structs/ValidateClaimsResult.html">ValidateClaimsResult</a></code> - an struct that list the various reasons for validation failure.
If the validation succeeds <code><a href="Structs/ValidateClaimsResult.html#/s:8SwiftJWT20ValidateClaimsResultV7successACvpZ">ValidateClaimsResult.success</a></code> is returned.
The <code>leeway</code> parameter is the <code>TimeInterval</code> in seconds that a standard <code>Date</code> claim will be valid outside of the specified time. This can be used to account for clock skew between issuers and verifiers.</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">validationResult</span> <span class="o">=</span> <span class="n">verified</span><span class="o">.</span><span class="nf">validateClaims</span><span class="p">(</span><span class="nv">leeway</span><span class="p">:</span> <span class="mi">10</span><span class="p">)</span>
<span class="k">if</span> <span class="n">validationResult</span> <span class="o">!=</span> <span class="o">.</span><span class="n">success</span> <span class="p">{</span>
<span class="nf">print</span><span class="p">(</span><span class="s">"Claims validation failed: "</span><span class="p">,</span> <span class="n">validationResult</span><span class="p">)</span>
<span class="p">}</span>
</code></pre>
<h3 id='decode-a-jwt-from-a-jwt-string' class='heading'>Decode a JWT from a JWT string</h3>
<p>A JWT struct can be initialized from a JWT string. If a JWTVerifier is provided it will be used to verify the signature before initialization</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">newJWT</span> <span class="o">=</span> <span class="k">try</span> <span class="kt">JWT</span><span class="o"><</span><span class="kt">MyClaims</span><span class="o">></span><span class="p">(</span><span class="nv">jwtString</span><span class="p">:</span> <span class="n">signedJWT</span><span class="p">,</span> <span class="nv">verifier</span><span class="p">:</span> <span class="n">jwtVerifier</span><span class="p">)</span>
</code></pre>
<h3 id='jwtencoder-and-jwtdecoder' class='heading'>JWTEncoder and JWTDecoder</h3>
<p>The JWTEncoder and JWTDecoder classes encode and decode JWT Strings using the same API as JSONEncoder and JSONDecoder:</p>
<pre class="highlight swift"><code> <span class="k">let</span> <span class="nv">jwtEncoder</span> <span class="o">=</span> <span class="kt">JWTEncoder</span><span class="p">(</span><span class="nv">jwtSigner</span><span class="p">:</span> <span class="n">jwtSigner</span><span class="p">)</span>
<span class="k">let</span> <span class="nv">jwtString</span> <span class="o">=</span> <span class="k">try</span> <span class="n">jwtEncoder</span><span class="o">.</span><span class="nf">encodeToString</span><span class="p">(</span><span class="n">myJWT</span><span class="p">)</span>
<span class="k">let</span> <span class="nv">jwtDecoder</span> <span class="o">=</span> <span class="kt">JWTDecoder</span><span class="p">(</span><span class="nv">jwtVerifier</span><span class="p">:</span> <span class="n">jwtVerifier</span><span class="p">)</span>
<span class="k">let</span> <span class="nv">jwt</span> <span class="o">=</span> <span class="k">try</span> <span class="n">jwtDecoder</span><span class="o">.</span><span class="nf">decode</span><span class="p">(</span><span class="kt">JWT</span><span class="o"><</span><span class="kt">MyClaims</span><span class="o">>.</span><span class="k">self</span><span class="p">,</span> <span class="nv">fromString</span><span class="p">:</span> <span class="n">jwtString</span><span class="p">)</span>
</code></pre>
<p>Because JWTEncoder and JWTDecoder conform to <a href="https://github.com/Kitura/KituraContracts/blob/master/Sources/KituraContracts/Contracts.swift">KituraContract’s</a> BodyEncoder and BodyDecoder protocols, they can be used as a <a href="https://developer.ibm.com/swift/2018/09/01/kitura-custom-encoders-and-decoders/">custom coder</a> in Codable routes for sending and receiving JWTs:</p>
<pre class="highlight swift"><code> <span class="n">router</span><span class="o">.</span><span class="n">encoders</span><span class="p">[</span><span class="kt">MediaType</span><span class="p">(</span><span class="nv">type</span><span class="p">:</span> <span class="o">.</span><span class="n">application</span><span class="p">,</span> <span class="nv">subType</span><span class="p">:</span> <span class="s">"jwt"</span><span class="p">)]</span> <span class="o">=</span> <span class="p">{</span> <span class="k">return</span> <span class="n">jwtEncoder</span> <span class="p">}</span>
<span class="n">router</span><span class="o">.</span><span class="n">decoders</span><span class="p">[</span><span class="kt">MediaType</span><span class="p">(</span><span class="nv">type</span><span class="p">:</span> <span class="o">.</span><span class="n">application</span><span class="p">,</span> <span class="nv">subType</span><span class="p">:</span> <span class="s">"jwt"</span><span class="p">)]</span> <span class="o">=</span> <span class="p">{</span> <span class="k">return</span> <span class="n">jwtDecoder</span> <span class="p">}</span>
</code></pre>
<p>This allows for the use of JWT’s in information exchange. By sending and receiving JWT’s you can ensure the sending is who they say they are and verify the content hasn’t been tampered with.</p>
<h2 id='api-documentation' class='heading'>API Documentation</h2>
<p>For more information visit our <a href="https://kitura.github.io/Swift-JWT/index.html">API reference</a>.</p>
<h2 id='community' class='heading'>Community</h2>
<p>We love to talk server-side Swift, and Kitura. Join our <a href="http://swift-at-ibm-slack.mybluemix.net/">Slack</a> to meet the team!</p>
<h2 id='license' class='heading'>License</h2>
<p>This library is licensed under Apache 2.0. Full license text is available in <a href="https://github.com/Kitura/Swift-JWT/blob/master/LICENSE">LICENSE</a>.</p>
</div>
</section>
</article>
</div>
<section class="footer">
<p>© 2020 <a class="link" href="https://github.com/Kitura/Swift-JWT" target="_blank" rel="external">IBM & Kitura Project Contributors</a>. All rights reserved. (Last updated: 2020-11-25)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
</div>
</html>