docs: fix broken OAuth2/OIDC policy examples (#8840)

## What / Why

The examples on the OAuth2/OIDC guide (`docs/docs/oauth-oidc.md`) fail
to compile on current OPA (v1+):

1. `claims := jwt.decode(input.token)[1]` uses an undefined built-in.
The correct name is `io.jwt.decode`, which the same page already uses
correctly further down (`jwt_unverified := io.jwt.decode(input.token)`).
2. The `jwt_verified := jwt_unverified { ... }` and `token := t { ... }`
rules are missing the `if` keyword required before a rule body in Rego
v1, so they fail to parse (`'if' keyword is required before rule body`).

## Changes
- `jwt.decode` -> `io.jwt.decode`
- add `if` before the `jwt_verified` and `token` rule bodies

These are minimal, semantics-preserving fixes so the copy-pasteable
examples work on a current OPA release.

Signed-off-by: Nikhil Jathar <22786232+mailnike@users.noreply.github.com>
This commit is contained in:
Nikhil J
2026-07-01 15:03:55 -05:00
committed by GitHub
parent c498b548ca
commit 81858aa542
+3 -3
View File
@@ -20,7 +20,7 @@ metadata_discovery(issuer) := http.send({
"force_cache_duration_seconds": 86400 # Cache response for 24 hours
}).body
claims := jwt.decode(input.token)[1]
claims := io.jwt.decode(input.token)[1]
metadata := metadata_discovery(claims.iss)
jwks_endpoint := metadata.jwks_uri
@@ -71,7 +71,7 @@ jwks_url := concat("?", [
])
jwks := jwks_request(jwks_url).raw_body
jwt_verified := jwt_unverified {
jwt_verified := jwt_unverified if {
io.jwt.verify_rs256(input.token, jwks)
}
@@ -85,7 +85,7 @@ Programmatically obtain an OAuth2 access token following the client credentials
```rego
package oauth2
token := t {
token := t if {
response := http.send({
"url": "https://authorization-server.example.com/token",
"method": "POST",