34 Commits
Author SHA1 Message Date
Trong Huu Nguyen a8399a8f8f test: merge split test files into their package test files
The redirect and provider fetch tests lived in files of their own for no
reason other than how they were added.
2026-08-10 12:36:09 +02:00
Trong Huu Nguyen 6cf48cd668 feat(openid/config): validate client assertion alg against provider metadata
Fail at startup rather than on the first token request when the identity
provider does not accept the client assertion algorithm. The check is
skipped when the provider omits the field, which is optional in Discovery.
2026-08-10 12:33:16 +02:00
Trong Huu Nguyen 2c708d554c feat(openid/config): require and expose the client JWK algorithm
Both the assertion signer and the provider validation derived the algorithm
from the key and had to handle a missing "alg" that NewClientConfig already
rejects. Validate it once at construction and keep the result.
2026-08-10 12:32:04 +02:00
Trong Huu Nguyen f3f76fccc8 refactor(config)!: rename id-token-signing-alg to jwks-fallback-alg
The flag never described id_token verification. It assigns an algorithm to
provider JWKS keys that omit "alg", which is a compatibility shim for
providers such as Azure and ID-porten.

BREAKING CHANGE: openid.id-token-signing-alg is now openid.jwks-fallback-alg.
A config file with the old key fails to start. The old environment variable
is ignored and the value falls back to RS256.
2026-08-10 12:30:25 +02:00
Trong Huu Nguyen 070a4127ae test: cover the hardened provider fetch and client redirect policy
Verified that the redirect test fails without the CheckRedirect policy:
without it the redirect is followed and the target is reached.
2026-07-28 12:52:45 +02:00
Trong Huu Nguyen 4d1d591448 fix(openid): bound and validate the provider metadata fetch
The metadata document was fetched with http.Get, which has no deadline,
so a hung connection blocked startup indefinitely. The response status
was never checked either, leaving an error page to surface as a JSON
decoding error.

The fetch now runs with a 10s deadline derived from the context passed
in from main, goes through the shared transport so it is traced and
pooled, and rejects any non-200 response.
2026-07-28 11:43:48 +02:00
Trong Huu Nguyen c56625d842 fix: check or explicitly ignore returned errors
Satisfies errcheck. Errors that carry no actionable information are
ignored explicitly: writes to an already-committed response, and closing
a fully read response body or file.

Test fixture setup asserts with require.NoError instead, since a failure
there means the fixture itself is broken.
2026-07-28 09:04:59 +02:00
Trong Huu Nguyen c02a932d72 feat(openid): support domain_hint for authorization grant 2026-03-03 09:38:24 +01:00
Trong Huu Nguyen 02842773d3 style: go fix 2026-03-03 08:35:11 +01:00
Trong Huu Nguyen da69847027 feat(openid): add opt-in toggle for typ header in accordance with RFC7523bis
Some providers require that the `typ` header has a value exactly equal
to `client-authentication+jwt` in accordance with changes introduced by
RFC7523bis.

This commit allows for opting in to setting the `typ` header with this new value.

The default behaviour is to use the previous de facto standard value, `JWT`.
Once the changes in RFC7523bis lands in the affected standards and
identity providers start supporting the new `typ` header (Entra ID being
notable for not supporting this as of this commit), we will default to
use `client-authentication+jwt`.
2025-08-26 08:29:27 +02:00
Trong Huu Nguyen 75ff84ba28 refactor: suppress some noisy startup logs 2025-07-09 13:33:40 +02:00
Trong Huu Nguyen 259bf635d1 chore(deps): bump github.com/lestrrat-go/jwx from v2 to v3 2025-05-21 10:38:26 +02:00
Trong Huu Nguyenandsindrerh2 909060d8fd feat(mock): implement PAR for identity provider
Co-authored-by: sindrerh2 <sindre.rodseth.hansen@nav.no>
2025-01-23 08:48:28 +01:00
Trong Huu Nguyenandsindrerh2 75f98debc5 feat(openid/client): validate iss parameter if provider declares authorization_response_iss_parameter_supported
Fixes #306.

Co-authored-by: sindrerh2 <sindre.rodseth.hansen@nav.no>
2025-01-21 09:39:21 +01:00
Trong Huu Nguyen e6297750d6 feat(openid): set expected default public JWK algorithm if the OP doesn't set them
This allows us to verify signatures without relying on heuristics used
by jws.WithInferAlgorithmFromKey() that may introduce security and
performance implications.
2024-11-05 21:08:46 +01:00
Trong Huu Nguyen df5c78b821 feat(openid/client): add support for the client_secret_post authentication method 2024-10-08 09:19:38 +02:00
Trong Huu Nguyen 1906024da0 feat(openid/acr): remove old values and backward compatibility for new idporten
We no longer expect nor accept tokens with old acr values during
validation as ID-porten no longer issues tokens with these values.

This also removes backward compatibility in cases where configured
values targeted the new ID-porten while using old ID-porten.

We still maintain an internal mapping from old values to new values
for forward compatibilty when using old values provided in the login
parameter and the `openid.acr-values` flag.
2024-06-27 12:34:16 +02:00
Trong Huu Nguyen d69cf79664 refactor: reduce noisy config logs
Fixes #262.
2024-06-26 14:51:05 +02:00
Trong Huu Nguyen f246fc7975 refactor(openid): move acr to own package 2023-10-11 14:25:12 +02:00
Trong Huu Nguyen e7799204b2 feat(openid): harden id_token validation 2023-08-15 21:30:41 +02:00
Trong Huu Nguyen 46852be025 feat(openid): prepare acr mappings for migration to new idporten 2023-05-25 15:54:29 +02:00
Trong Huu Nguyen fd73a0a83e refactor(openid/config): more descriptive error message for unsupported values 2023-03-21 09:11:30 +01:00
Trong Huu Nguyen 473e4a95a7 refactor: remove loginstatus
Loginstatus is no longer needed with the SSO setup.
Fixes #50.
2023-02-10 14:58:17 +01:00
Trong Huu Nguyen bd748b9cef refactor(openid/provider): use name from config instead of indirection layer 2023-02-10 14:57:56 +01:00
Trong Huu Nguyen 92ee6313c5 refactor: remove unnecessary interfaces 2022-09-02 17:39:27 +02:00
Trong Huu Nguyen c8f48335d4 refactor(openid/config): extract getter for ingresses 2022-09-02 15:17:36 +02:00
Trong Huu Nguyen d5bbca9897 feat: rudimentary support for refresh tokens 2022-08-26 14:32:39 +02:00
Trong Huu Nguyen 5a50ba7c3a feat: support multiple ingresses
Replace hardcoded callback URLs with dynamic generation
of URLs based on incoming requests. These are validated against
a pre-registered list of ingresses for which Wonderwall is considered
authorative for.

We also preserve the cookie behaviour; the most specific ingress path
and domain is used for the cookies.

The `url` package has been moved to the `handler` package, and its
implementation refactored slightly for readability and DRY.
2022-08-17 20:43:56 +02:00
Trong Huu Nguyen 242dc12be9 refactor(openid/config): remove unused field 2022-07-20 15:25:28 +02:00
Trong Huu Nguyen eac2d5789d refactor: passthrough for consistency in openid configuration 2022-07-20 09:58:49 +02:00
Trong Huu Nguyen 3e62683cad refactor: use pointer receivers when possible 2022-07-19 19:24:28 +02:00
Trong Huu Nguyen aab249d78a refactor(jwt): skip parsing access tokens
Access Tokens are not necessarily JWTs. We also don't
have to validate them as we only pass it on as an opaque
string.

This also means that we don't log the JTI access tokens
anymore.

We also simplify handling of oidc callbacks.
2022-07-14 12:14:25 +02:00
Trong Huu Nguyen 42938ee8b3 refactor(handler): deduplicate configuration 2022-07-05 14:43:40 +02:00
Trong Huu Nguyen 1f5635239a refactor: split out openid client, config and provider
There's a bunch of changes here, but in essence:

- split out openid configuration
- separate openid configuration between client/rp and provider
- consolidate client and provider related code in separate packages

These changes allow for simplification of the Handler, as well as a
bunch of test/mock code as the configuration is now instantiated
seperately from the client/provider code.
2022-07-05 13:09:00 +02:00