Mercurial > hg > nginx-site
comparison xml/en/docs/njs/examples.xml @ 2780:bf641527bd3d
Updated jwt_field example in njs Examples.
author | Yaroslav Zhuravlev <yar@nginx.com> |
---|---|
date | Fri, 15 Oct 2021 20:14:49 +0100 |
parents | 9cafae0b7ef3 |
children | 24b379907b0f |
comparison
equal
deleted
inserted
replaced
2779:b6bbdce8c659 | 2780:bf641527bd3d |
---|---|
7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd"> | 7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd"> |
8 | 8 |
9 <article name="Examples" | 9 <article name="Examples" |
10 link="/en/docs/njs/examples.html" | 10 link="/en/docs/njs/examples.html" |
11 lang="en" | 11 lang="en" |
12 rev="19"> | 12 rev="20"> |
13 | 13 |
14 <section id="summary"> | 14 <section id="summary"> |
15 | 15 |
16 <para> | 16 <para> |
17 The examples work since | 17 The examples work since |
146 | 146 |
147 <section id="jwt_field" name="Getting Arbitrary Field from JWT | 147 <section id="jwt_field" name="Getting Arbitrary Field from JWT |
148 as nginx Variable"> | 148 as nginx Variable"> |
149 | 149 |
150 <para> | 150 <para> |
151 In the following example, the <literal>sub</literal> field | |
152 is extracted from JWT payload. | |
153 The JWT token is taken from the <header>Authorization</header> header. | |
154 </para> | |
155 | |
156 <para> | |
151 <path>nginx.conf</path>: | 157 <path>nginx.conf</path>: |
152 <example> | 158 <example> |
153 js_import http.js; | 159 js_import http.js; |
154 | 160 |
155 js_set $jwt_payload_sub http.jwt_payload_sub; | 161 js_set $jwt_payload_sub http.jwt_payload_sub; |
174 return { headers:parts[0], payload: parts[1] }; | 180 return { headers:parts[0], payload: parts[1] }; |
175 } | 181 } |
176 | 182 |
177 function jwt_payload_sub(r) { | 183 function jwt_payload_sub(r) { |
178 return jwt(r.headersIn.Authorization.slice(7)).payload.sub; | 184 return jwt(r.headersIn.Authorization.slice(7)).payload.sub; |
185 // when the token is provided as the "myjwt" argument | |
186 // return jwt(r.args.myjwt).payload.sub; | |
179 } | 187 } |
180 | 188 |
181 export default {jwt_payload_sub}; | 189 export default {jwt_payload_sub}; |
182 </example> | 190 </example> |
183 </para> | 191 </para> |