245 Commits

Author SHA1 Message Date
Wim Van Laer
0ad2480e24 fix!: allow expires to be an integer wrapped in a string value (#821)
Certain providers, for example Entra ID, return durations as quoted
strings instead of JSON numbers. This is a deviation from the standard.
This change allows for the successful parsing of such quoted duration
strings.

BREAKING CHANGE: The `expires_in field` has changed from type `int64` to
`oidc.Duration` for various token response payloads.

fixes https://github.com/zitadel/oidc/issues/815

### Definition of Ready

- [x] I am happy with the code
- [x] Short description of the feature/issue is added in the pr
description
- [x] PR is linked to the corresponding user story
- [x] Acceptance criteria are met
- [x] All open todos and follow ups are defined in a new ticket and
justified
- [ ] Deviations from the acceptance criteria and design are agreed with
the PO and documented.
- [x] No debug or dead code
- [x] My code has no repetitions
- [x] Critical parts are tested automatically
- [ ] Where possible E2E tests are implemented
- [ ] Documentation/examples are up-to-date
- [ ] All non-functional requirements are met
- [ ] Functionality of the acceptance criteria is checked manually on
the dev system.
2026-01-07 13:02:22 +01:00
Wim Van Laer
a4ecfb1c09 Merge branch 'main' into merge-main
# Conflicts:
#	README.md
#	example/client/app/app.go
#	example/server/exampleop/op.go
#	example/server/main.go
#	pkg/client/client.go
#	pkg/client/rp/relying_party.go
#	pkg/client/rp/relying_party_test.go
#	pkg/client/tokenexchange/tokenexchange.go
#	pkg/crypto/key_test.go
#	pkg/oidc/token.go
#	pkg/oidc/verifier.go
#	pkg/op/auth_request.go
#	pkg/op/device.go
#	pkg/op/server_http_routes_test.go
#	pkg/op/token.go
#	pkg/op/token_refresh.go
2025-11-28 11:19:02 +01:00
Livio Spring
adddf0e4b3 refactor: deprecate proprietary key file use for JWT Profile (#801)
While reviewing #750, we noticed that the `KeyFile` struct and
corresponding methods are proprietary to Zitadel and should have never
been part of the pure OIDC library.

This PR deprecates the corresponding parts. For users of Zitadel, the
corresponding code is moved to zitadel/zitadel-go#516

### Definition of Ready

- [x] I am happy with the code
- [x] Short description of the feature/issue is added in the pr
description
- [x] PR is linked to the corresponding user story
- [x] Acceptance criteria are met
- [ ] All open todos and follow ups are defined in a new ticket and
justified
- [ ] Deviations from the acceptance criteria and design are agreed with
the PO and documented.
- [x] No debug or dead code
- [x] My code has no repetitions
- [x] Critical parts are tested automatically
- [ ] Where possible E2E tests are implemented
- [x] Documentation/examples are up-to-date
- [x] All non-functional requirements are met
- [x] Functionality of the acceptance criteria is checked manually on
the dev system.
2025-09-23 08:44:48 +02:00
Tim Möhlmann
c85da539c0 chore(go): add support for 1.25 (#798)
- Add Go 1.25 to the test matrix
- Oldest supported Go version is now 1.24, as required for
https://github.com/zitadel/oidc/pull/796
- Fix non-constant format string build errors

### Definition of Ready

- [x] I am happy with the code
- [x] Short description of the feature/issue is added in the pr
description
- [x] PR is linked to the corresponding user story
- [x] Acceptance criteria are met
- [x] All open todos and follow ups are defined in a new ticket and
justified
- [x] Deviations from the acceptance criteria and design are agreed with
the PO and documented.
- [x] No debug or dead code
- [x] My code has no repetitions
- [x] Critical parts are tested automatically
- [x] Where possible E2E tests are implemented
- [x] Documentation/examples are up-to-date
- [x] All non-functional requirements are met
- [x] Functionality of the acceptance criteria is checked manually on
the dev system.
2025-09-08 12:05:27 +03:00
Ayato
5d37097a96 chore(op): fix parameter name typo in GetKeyByIDAndClientID (#779)
Fix parameter name typo in `GetKeyByIDAndClientID`

### Definition of Ready
- [x] I am happy with the code
- [x] Short description of the feature/issue is added in the pr
description
- [ ] PR is linked to the corresponding user story
- [ ] Acceptance criteria are met
- [ ] All open todos and follow ups are defined in a new ticket and
justified
- [ ] Deviations from the acceptance criteria and design are agreed with
the PO and documented.
- [ ] No debug or dead code
- [ ] My code has no repetitions
- [ ] Critical parts are tested automatically
- [ ] Where possible E2E tests are implemented
- [ ] Documentation/examples are up-to-date
- [ ] All non-functional requirements are met
- [ ] Functionality of the acceptance criteria is checked manually on
the dev system.

Co-authored-by: Stefan Benz <46600784+stebenz@users.noreply.github.com>
2025-08-05 12:25:17 +00:00
mqf20
3edc81ed9a feat: allow setting op.Crypto during provider setup (#778)
Add a `op.WithCrypto` `op.Option` that allows developers to specify
their custom `op.Crypto` implementations during setup. If the
`op.Option` is used, it will override `op.Config.CryptoKey`.

Closes https://github.com/zitadel/oidc/issues/736.

### Definition of Ready

- [x] I am happy with the code
- [x] Short description of the feature/issue is added in the pr
description
- [x] PR is linked to the corresponding user story
- [ ] Acceptance criteria are met
- [ ] All open todos and follow ups are defined in a new ticket and
justified
- [ ] Deviations from the acceptance criteria and design are agreed with
the PO and documented.
- [x] No debug or dead code
- [ ] My code has no repetitions
- [ ] Critical parts are tested automatically
- [ ] Where possible E2E tests are implemented
- [x] Documentation/examples are up-to-date
- [ ] All non-functional requirements are met
- [ ] Functionality of the acceptance criteria is checked manually on
the dev system.

---------

Signed-off-by: mqf20 <mingqingfoo@gmail.com>
Co-authored-by: Tim Möhlmann <tim+github@zitadel.com>
2025-08-05 12:00:11 +00:00
Sianao
1fb34f3d41 fix: add redirect_uri decoded (#775)
### Definition of Ready

This PR introduces a redirect_uri decoding step (url.QueryUnescape) in
the authorization request validation logic.
Libraries such as
[golang.org/x/oauth2](https://cs.opensource.google/go/x/oauth2/+/refs/tags/v0.30.0:oauth2.go;l=184)
automatically encode the redirect_uri using url.Values.Encode(). This
means the incoming URI is percent-encoded (e.g.,
https%3A%2F%2Fclient.example.com%2Fcallback), and the server must decode
it before performing string comparisons.

- [x] I am happy with the code
- [x] Short description of the feature/issue is added in the pr
description
- [x] PR is linked to the corresponding user story
- [x] Acceptance criteria are met
- [x] All open todos and follow ups are defined in a new ticket and
justified
- [x] Deviations from the acceptance criteria and design are agreed with
the PO and documented.
- [x] No debug or dead code
- [x] My code has no repetitions
- [x] Critical parts are tested automatically
- [x] Where possible E2E tests are implemented
- [x] Documentation/examples are up-to-date
- [x] All non-functional requirements are met
- [x] Functionality of the acceptance criteria is checked manually on
the dev system.

Co-authored-by: sianao <me@sianao.site>
2025-08-04 11:48:51 +00:00
Marc Alvarez
baf65b9a8c chore(op): clarify refresh token parameter names and improve code readability (#756)
### Context

While implementing the Storage interface, I discovered that several
parameter names were misleading:
- Parameters named `refreshTokenID` and `newRefreshTokenID` actually
contain the full token values, not IDs
- This naming inconsistency caused confusion about what values should be
passed/returned
- The example implementations already use the semantically correct names
(`refreshToken`, `newRefreshToken`), creating a mismatch with the
interface definition

  ## Solution

This PR aligns the interface parameter names with their actual purpose
and with the existing example implementations.

  ## Changes

  1. **Storage interface parameter renames:**
     - `TokenRequestByRefreshToken`: `refreshTokenID` → `refreshToken`
- `CreateAccessAndRefreshTokens`: `newRefreshTokenID` →
`newRefreshToken`

  2. **Improved code readability in token.go:**
     - Made bare returns explicit for better clarity
     - Added documentation explaining the token creation flow
     - Clarified why `CreateAccessToken` also returns refresh tokens

  ## Impact

- **Breaking change**: No - these are parameter name changes in the
interface definition only
  - **Behavior change**: No - all logic remains unchanged
- **Documentation**: Improved with clearer parameter names and added
explanations

  ## Testing

- Ran existing tests (some timing-related test failures are pre-existing
and unrelated to these changes)
  - Verified example implementations already use the new parameter names

### Definition of Ready

- [X] I am happy with the code
- [X] Short description of the feature/issue is added in the pr
description
- [ ] PR is linked to the corresponding user story
- [ ] Acceptance criteria are met
- [ ] All open todos and follow ups are defined in a new ticket and
justified
- [ ] Deviations from the acceptance criteria and design are agreed with
the PO and documented.
- [X] No debug or dead code
- [X] My code has no repetitions
- [ ] Critical parts are tested automatically
- [ ] Where possible E2E tests are implemented
- [X] Documentation/examples are up-to-date
- [ ] All non-functional requirements are met
- [ ] Functionality of the acceptance criteria is checked manually on
the dev system.
2025-08-04 14:13:11 +03:00
Jan-Otto Kröpke
21e830e275 feat: exclude OTEL instrumentation via build tag (#770)
* feat: exclude OTEL instrumentation via build tag

* add readme
2025-07-16 11:29:59 +00:00
Livio Spring
f94bd541d7 feat: update end session request to pass all params according to specification (#754)
* feat: update end session request to pass all params according to specification

* register encoder
2025-06-05 13:19:51 +02:00
Ayato
4f0ed79c0a fix(op): Add mitigation for PKCE Downgrade Attack (#741)
* fix(op): Add mitigation for PKCE downgrade attack

* chore(op): add test for PKCE verification
2025-04-29 14:33:31 +00:00
Masahito Osako
5913c5a074 feat: enhance authentication response handling (#728)
- Introduced CodeResponseType struct to encapsulate response data.
- Added handleFormPostResponse and handleRedirectResponse functions to manage different response modes.
- Created BuildAuthResponseCodeResponsePayload and BuildAuthResponseCallbackURL functions for better modularity in response generation.
2025-04-29 14:17:28 +00:00
Ayato
c51628ea27 feat(op): always verify code challenge when available (#721)
Finally the RFC Best Current Practice for OAuth 2.0 Security has been approved.

According to the RFC:

> Authorization servers MUST support PKCE [RFC7636].
> 
> If a client sends a valid PKCE code_challenge parameter in the authorization request, the authorization server MUST enforce the correct usage of code_verifier at the token endpoint.

Isn’t it time we strengthen PKCE support a bit more?

This PR updates the logic so that PKCE is always verified, even when the Auth Method is not "none".
2025-03-24 18:00:04 +02:00
Iraq
2c64de821d chore: updating go to 1.24 (#726)
* chore: updating go to 1.24

* fixup! chore: updating go to 1.24

* fixup! fixup! chore: updating go to 1.24

* fix device test (drop read error)

* drop older go versions

* drop unrelated formatter changes

---------

Co-authored-by: Iraq Jaber <IraqJaber@gmail.com>
Co-authored-by: Tim Möhlmann <tim+github@zitadel.com>
2025-03-14 16:12:26 +01:00
BitMasher
7a767d8568 feat: add CanGetPrivateClaimsFromRequest interface (#717) 2025-03-12 14:00:29 +02:00
minami yoshihiko
4ef9529012 feat: support for session_state (#712)
* add default signature algorithm

* implements session_state in auth_request.go

* add test

* Update pkg/op/auth_request.go

link to the standard

Co-authored-by: Tim Möhlmann <muhlemmer@gmail.com>

* add check_session_iframe

---------

Co-authored-by: Tim Möhlmann <tim+github@zitadel.com>
Co-authored-by: Tim Möhlmann <muhlemmer@gmail.com>
2025-02-24 10:50:38 +00:00
Ramon
de2fd41f40 fix: allow native clients to use https:// on localhost redirects (#691) 2025-01-17 13:53:19 +00:00
isegura-eos-eng
6d20928028 refactor: mark pkg/strings as deprecated in favor of stdlib (#680)
* refactor: mark pkg/strings as deprecated in favor of stdlib

* format: reword deprecate notice and use doc links
2024-11-15 18:47:32 +02:00
isegura-eos-eng
897c720070 fix(op): add scope to access token scope (#664) 2024-11-13 08:49:55 +00:00
Kevin Schoonover
8afb8b8d5f feat(pkg/op): allow custom SupportedScopes (#675)
Co-authored-by: Tim Möhlmann <tim+github@zitadel.com>
2024-11-12 15:06:24 +00:00
Livio Spring
f1e4cb2245 feat(OP): add back channel logout support (#671)
* feat: add configuration support for back channel logout

* logout token

* indicate back channel logout support in discovery endpoint
2024-10-30 08:44:31 +00:00
Tim Möhlmann
1e75773eaa fix(op): initialize http Headers in response objects (#637)
* fix(op): initialize http Headers in response objects

* fix test

---------

Co-authored-by: Livio Spring <livio.a@gmail.com>
2024-08-21 09:34:26 +02:00
Tim Möhlmann
0aa61b0b98 fix(op): do not redirect to unverified uri on error (#640)
Closes #627
2024-08-21 09:29:14 +02:00
Elio Bischof
6f0a630ad4 fix: overwrite redirect content length (#632)
* fix: overwrite redirect content length

* copy redirect struct headers
2024-08-06 12:58:52 +03:00
Tim Möhlmann
a7b5355580 feat(op): allow scope without openid (#613)
This changes removes the requirement of the openid scope to be set for all token requests.
As this library also support OAuth2-only authentication mechanisms we still want to sanitize requested scopes, but not enforce the openid scope.

Related to https://github.com/zitadel/zitadel/discussions/8068
2024-06-13 08:16:46 +02:00
Tim Möhlmann
37ca0e472a feat(op): authorize callback handler as argument in legacy server registration (#598)
This change requires an additional argument to the op.RegisterLegacyServer constructor which passes the Authorize Callback Handler.
This allows implementations to use their own handler instead of the one provided by the package.
The current handler is exported for legacy behavior.

This change is not considered breaking, as RegisterLegacyServer is flagged experimental.

Related to https://github.com/zitadel/zitadel/issues/6882
2024-04-30 20:27:12 +03:00
Tim Möhlmann
33f8df7eb2 feat(deps): update go-jose to v4 (#588)
This change updates to go-jose v4, which was a new major release.

jose.ParseSigned now expects the supported signing algorithms to be passed, on which we previously did our own check. As they use a dedicated type for this, the slice of string needs to be converted. The returned error also need to be handled in a non-standard way in order to stay compatible.

For OIDC v4 we should use the jose.SignatureAlgorithm  type directly and wrap errors, instead of returned static defined errors.

Closes #583
2024-04-11 18:13:30 +03:00
Tim Möhlmann
14e8529b68 chore(next): v4 module for development 2024-04-02 14:23:12 +03:00
Tim Möhlmann
4d63d68c9e feat(op): allow setting the actor to Token Requests (#569)
For impersonation token exchange we need to persist the actor throughout token requests, including refresh token.
This PR adds the optional TokenActorRequest interface which allows to pass such actor.
2024-03-14 06:57:44 +00:00
adlerhurst
1b94f796eb move tracer to client,
add tracing in rs, client
2024-03-13 15:45:03 +01:00
adlerhurst
0fe7c3307f fix parse 2024-03-07 15:25:23 +01:00
adlerhurst
7069813ec7 correct span names 2024-03-07 10:44:24 +01:00
adlerhurst
88209ac11d fix tests 2024-03-06 19:08:48 +01:00
adlerhurst
bdcccc3303 feat(client): tracing in rp 2024-03-06 18:39:27 +01:00
adlerhurst
d18aba8cb3 feat(rp): extend tracing 2024-03-06 18:38:37 +01:00
Ayato
5ef597b1db feat(op): Add response_mode: form_post (#551)
* feat(op): Add response_mode: form_post

* Fix to parse the template ahead of time

* Fix to render the template in a buffer

* Remove unnecessary import

* Fix test

* Fix example client setting

* Make sure the client not to reuse the content of the response

* Fix error handling

* Add the response_mode param

* Allow implicit flow in the example app

* feat(rp): allow form_post in code exchange callback handler

---------

Co-authored-by: Tim Möhlmann <tim+github@zitadel.com>
2024-03-05 15:04:43 +02:00
Tim Möhlmann
972b8981e5 feat: go 1.22 and slog migration (#557)
This change adds Go 1.22 as a build target and drops support for Go 1.20 and older. The golang.org/x/exp/slog import is migrated to log/slog.

Slog has been part of the Go standard library since Go 1.21. Therefore we are dropping support for older Go versions. This is in line of our support policy of "the latest two Go versions".
2024-02-28 10:44:14 +01:00
Tim Möhlmann
045b59e5a5 fix(op): allow expired id token hints in authorize (#527)
Like https://github.com/zitadel/oidc/pull/522 for end session,
this change allows passing an expired ID token hint to the authorize endpoint.
2024-02-01 13:49:22 +01:00
Tim Möhlmann
e9bd7d7bac feat(op): split the access and ID token hint verifiers (#525)
* feat(op): split the access and ID token hint verifiers

In zitadel we require different behaviors wrt public key expiry between access tokens and ID token hints.
This change splits the two verifiers in the OP.
The default is still based on Storage and passed to both verifier fields.

* add new options to tests
2024-01-26 16:44:50 +01:00
Tim Möhlmann
b8e520afd0 fix: allow expired ID token hint to end sessions (#522)
* fix: allow expired ID token hint to end sessions

This change adds a specific error for expired ID Token hints, including too old "issued at" and "max auth age".
The error is returned VerifyIDTokenHint so that the end session handler can choose to ignore this error.

This fixes the behavior to be in line with [OpenID Connect RP-Initiated Logout 1.0, section 4](https://openid.net/specs/openid-connect-rpinitiated-1_0.html#ValidationAndErrorHandling).

* Tes IDTokenHintExpiredError
2024-01-19 11:30:51 +01:00
Tim Möhlmann
57d04e7465 fix: don't force server errors in legacy server (#517)
* fix: don't force server errors in legacy server

* fix tests and be more consistent with the returned status code
2024-01-17 16:06:45 +01:00
Tim Möhlmann
844e2337bb fix(op): check redirect URI in code exchange (#516)
This changes fixes a missing redirect check in the Legacy Server's Code Exchange handler.
2024-01-16 07:18:41 +01:00
Tim Möhlmann
c37ca25220 feat(op): allow double star globs (#507)
Related to https://github.com/zitadel/zitadel/issues/5110
2024-01-05 17:30:17 +02:00
Tim Möhlmann
b300027cd7 feat(op): ID token for device authorization grant (#500) 2023-12-18 08:39:39 +01:00
snow
7bdaf9c71d feat(op): User-configurable claims_supported (#495)
* User-configurable claims_supported

* Use op.SupportedClaims instead of interface
2023-12-17 12:06:42 +00:00
Stephen Andary
9d12d1d900 feat(op): PKCE Verification in Legacy Server when AuthMethod is not NONE and CodeVerifier is not Empty (#496)
* add logic for legacy server pkce verification when auth method is not None, and code verifier is not empty.

* update per Tim's direction
2023-12-07 17:36:03 +02:00
Stefan Benz
a8ef8de87b feat(op): JWT profile verifier with keyset
feat(op): JWT profile verifier with keyset
2023-11-21 10:26:57 +01:00
Kory Prince
7b64687990 feat: Allow CORS policy to be configured (#484)
* Add configurable CORS policy in OpenIDProvider

* Add configurable CORS policy to Server

* remove duplicated CORS middleware

* Allow nil CORS policy to be set to disable CORS middleware

* create a separate handler on webServer so type assertion works in tests
2023-11-17 15:33:48 +02:00
Tim Möhlmann
f6bd17e8db correct comment 2023-11-13 19:28:01 +02:00
Tim Möhlmann
c6b5544516 Merge branch 'main' into perf-introspection 2023-11-13 18:17:09 +02:00