#!/usr/bin/env bash # The claim checks that decide whether a correctly signed token is yours. # Usage: ./scripts/issuer-audience-demo.sh "" set -eu . "$(dirname "$0")/lib.sh" PROFILES="${1:-unknown}" head1 "resource server profiles: $PROFILES" head1 "1. A correct token" T=$(stub_token "sub=alice&aud=reports-api") claims "$T" call "GET /api/me" "$RS/api/me" "$T" head1 "2. Signed by the right key, but iss says something else" echo "The signature verifies. The key is the same key. Only the string differs." T=$(stub_token "sub=alice&aud=reports-api&issuerOverride=http://localhost:9000/other") claims "$T" call "GET /api/me" "$RS/api/me" "$T" head1 "3. A token minted for a different service in the same realm" echo "This is the one that silently works when nothing checks aud." T=$(stub_token "sub=alice&aud=billing-api") claims "$T" call "GET /api/me" "$RS/api/me" "$T" head1 "4. Expired 90 seconds ago" echo "The default clock skew is 60s, so a token has to be more than a minute stale" echo "before JwtTimestampValidator refuses it." T=$(stub_token "sub=alice&aud=reports-api&issuedAgoSeconds=120&expiresInSeconds=30") call "GET /api/me" "$RS/api/me" "$T" head1 "5. Expired 30 seconds ago - inside the default clock skew" T=$(stub_token "sub=alice&aud=reports-api&issuedAgoSeconds=60&expiresInSeconds=30") call "GET /api/me" "$RS/api/me" "$T" head1 "6. typ=at+jwt, which RFC 9068 says an access token SHOULD carry" echo "The default validator stack contains JwtTypeValidator.jwt(), which accepts only an" echo "absent typ or typ=JWT. Whether this passes depends on the attyp profile." T=$(stub_token "sub=alice&aud=reports-api&typ=at%2Bjwt") claims "$T" call "GET /api/me" "$RS/api/me" "$T" head1 "7. No token at all" call "GET /api/me" "$RS/api/me" call "GET /api/public/ping" "$RS/api/public/ping" head1 "8. The endpoint nobody configured" echo "Spring Security 7 publishes RFC 9728 protected resource metadata and points the" echo "WWW-Authenticate challenge at it. It answers without a token." call "GET /.well-known/oauth-protected-resource" "$RS/.well-known/oauth-protected-resource"