Agent Harness Tutorial · End to end · Zoom level 3
How we take care of it: verify the token
verify the token catches a forged or expired sign-in.
How we took care of it.
- PyJWT checks the RS256 signature against Entra's published keys (cached for 5 minutes).
- It checks the issuer, the audience (it must be issued for this app) and the expiry.
- Rohan's customer id is read from the token. Nothing in the message can change it.
- His scopes (claims:read, claims:write) become the Identity used by every later check.
| It reads | the Authorization: Bearer token sent with every message |
| Kind | rule |
| Provided by | harness |
| If it fails | 401; nothing else runs |
| Where in the code | verify_entra() · H identity/entra.py:104 |
| Runs at | 1 · Before the loop |
Real exampleA message saying "I am PH-2002" changes nothing: the identity is PH-1001, from the token.
More on this: Front door.
How it is done: the real code
Cut from the live repositories each time the site is built, so it always matches what runs.
def verify_entra(
token: str,
*,
issuer: Issuer,
now: int | None = None,
role_scopes: RoleScopes | None = None,
holder_claim: str = CLAIM_CUSTOMER,
) -> Principal:
"""`identity.verify` for Entra's claims: the same signature check, issuer,
audience and expiry (`decode`), the session named by `uti`, and an app role
granting the scopes `role_scopes` gives it.
`holder_claim` is where the customer id is read from. Entra writes a
directory extension attribute as `extn.<name>` (claims-fnol-azure A2), not
`customer_id`, so the overlay names it, and the far end reads the same name."""
claims = decode(token, issuer=issuer, now=now, require=("uti",))
party = claims.get("azp")
return Principal(
subject=str(claims["sub"]),
customer_id=holder_of(claims.get(holder_claim)),
scopes=frozenset(entra_scopes(claims, role_scopes)),
session=str(claims["uti"]),
party=party if isinstance(party, str) else None,
token=token,
)