Sandbox
The repo ships a runnable sandbox — one Go binary + one Keycloak container — that lets you step through a real SAML and a real OIDC round-trip without touching your own infrastructure.
Run it
# 1. pre-provisioned Keycloak on :8081 (admin / admin)
make sandbox.up
# 2. demo app on :8080
make sandbox.runVisit http://localhost:8080 and pick one of the login buttons. Sign in as:
| user | password | groups |
|---|---|---|
| alice | password | admins |
| bob | password | users |
You'll be bounced back to the demo app with a session. The card shows which protocol authenticated you, and /whoami dumps the raw Subject.
What's set up
Keycloak realm
examples/sandbox/realm-export.json is imported on first boot. It defines:
- Two users (alice, bob) with plaintext passwords seeded for convenience.
- Two groups:
admins(alice) andusers(bob). - An OIDC client
gosso-oidcwith standard flow, PKCE, agroupsclaim mapper, andoffline_accessscope enabled. - A SAML client whose entity ID is
http://localhost:8080/saml/metadataand whose attribute mappers emit Azure-AD-style URIs. This means the library's defaultAzureADAttributeMapworks unmodified against this realm.
Demo app
examples/sandbox/main.go (~300 LOC). An in-memory session store keyed by a signed random cookie. Two OnAuthenticated callbacks — one per protocol — write into the same store; the root page renders the stored subject. Note that it keeps only a normalised projection of Subject (plus RawIDToken and SessionIndex for logout), because the raw SAML assertion and OIDC ID token are not JSON-friendly.
Native-app broker
The OIDC RP also carries the native broker for a public client sandbox-cli with the loopback redirect http://127.0.0.1:8090/callback. It mounts /oidc/app/authorize, /oidc/app/token and /oidc/app/revoke, keeps codes and sessions in MongoDB, and mints opaque 2-minute access tokens that /app/whoami accepts as Authorization: Bearer. examples/nativeapp is the CLI client:
make sandbox.app.check # protocol checks, no login
make sandbox.app # login, whoami, refresh, whoami, revoke
make sandbox.app.reuse # replay an old refresh token: session revoked
make sandbox.app.concurrent # two concurrent refreshes both succeed
make sandbox.app.outage # with sandbox.idp.stop / sandbox.idp.start: 503, session kept
make sandbox.app.signout # with sandbox.idp.signout: IdP ends the session
make sandbox.app.restart # a session survives a restart of the demo app
make sandbox.mongo # the broker's stored codes, sessions and indexesEach scenario prints PASS or FAIL. See examples/sandbox/README.md for the full testing playbook.
Certificates
A dev-only SP cert lives at examples/sandbox/certs/sp.{crt,key}. Do not use outside this sandbox. Regenerate with make sandbox.certs.
Tear down
make sandbox.down # stops Keycloak, removes volumesThings to try
- Log in via OIDC, hit
/oidc/logout— watch Keycloak invalidate the session viaid_token_hintand bounce you back to the landing page. - Log in via SAML, then open a private tab to confirm the session is tied to the cookie, not to the IdP.
- Disable the
groupsprotocol mapper on the SAML client (Keycloak admin UI on :8081) and seeSubject.Groupsbecome empty. - Flip
oidc.WithUserInfo(true)on and off inmain.goand compare the/whoamioutput. - Replace
AzureADAttributeMapwith one of your own URIs to reproduce a different IdP's shape.