#!/usr/bin/env bash # Why a failed token request sometimes answers 302 -> /login instead of 401. set -u cd "$(dirname "$0")/.." . scripts/lib.sh OUT=../docs/output/as-entrypoint-accept.txt LABEL="${1:-}" mkdir -p ../docs/output probe() { local accept="$1" desc="$2" echo "--- $desc" echo "\$ curl -H 'Accept: $accept' -d grant_type=authorization_code -d code=bogus \\" echo " -d client_id=demo-spa $AS/oauth2/token" curl -s -i -H "Accept: $accept" -d grant_type=authorization_code -d code=bogus \ -d client_id=demo-spa "$AS/oauth2/token" \ | sed -n '1p;/^[Ll]ocation:/p;/^WWW-Authenticate/p' echo } { section "Public client, failed authentication at the token endpoint [$LABEL]" echo "A public client authenticates at /oauth2/token by presenting a code_verifier." echo "With no verifier there is nothing to authenticate with, so the request falls" echo "through to the AuthenticationEntryPoint - and which entry point runs depends on" echo "the Accept header." echo probe "*/*" "Accept: */* (curl's default, and most HTTP clients')" probe "application/json" "Accept: application/json" probe "text/html" "Accept: text/html (a browser)" section "Confidential client with a wrong secret, for contrast" echo "This never reaches the entry point: OAuth2ClientAuthenticationFilter writes the" echo "error itself, so the Accept header makes no difference." curl -s -i -u demo-web:wrong -d grant_type=client_credentials "$AS/oauth2/token" \ | sed -n '1p;/^[Ll]ocation:/p' } >> "$OUT" 2>&1 sed -i 's/[[:space:]]*$//' "$OUT" echo "appended $LABEL to $OUT"