Skip to content

Commit 57e62eb

Browse files
committed
docs: add claims-based authorization section to README
1 parent 1aadf9b commit 57e62eb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,33 @@ end
123123

124124
```
125125

126+
### Claims-based Authorization
127+
128+
Some backends are restricted so that only certain users can access them, allowing us to restrict access based on [Claims].
129+
130+
See the Lua configuration `validate_claims` below:
131+
132+
```lua
133+
local libjwt = require("resty.libjwt")
134+
libjwt.validate({
135+
jwks_files = {"/etc/nginx/jwks.json"},
136+
validate_claims = {
137+
"iss" = {exact = "myiss"},
138+
"aud" = {one_of = {"audience1", "audience2"}},
139+
"sub" = {pattern = ".*@mycompany%.com"},
140+
},
141+
})
142+
```
143+
144+
#### Validation Types
145+
146+
Note that we have 3 types of validations:
147+
148+
* `{exact = "TERM"}`: ensures that a claim must be exactly equal to TERM, otherwise the user will receive a 403 (Forbidden)
149+
* `{one_of = {"TERM1", "TERM2"}}`: allows a list of permitted CLAIMS, if not in the list the user will receive a 403 (Forbidden)
150+
* `{pattern = ".*@mycompany%.com"}`: Allows validation using [Lua Pattern Matching](https://www.lua.org/pil/20.2.html), an expression language similar to Regex. In the example above, we can ensure that only users from the mycompany.com domain can access; if the expression doesn't match, the user will receive a 403 (Forbidden)
151+
152+
126153
## Final Considerations
127154

128155
- Ensure that the **jwks.json** file is accessible by Nginx.

0 commit comments

Comments
 (0)