mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-06 09:13:19 +03:00
[PR #566] [MERGED] feat: JWT bearer assertions for client authentication #725
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/pocket-id/pocket-id/pull/566
Author: @ItalyPaleAle
Created: 5/25/2025
Status: ✅ Merged
Merged: 6/6/2025
Merged by: @stonith404
Base:
main← Head:client-assertions-2📝 Commits (10+)
6546467WIP: backend implementationdfd5217Fixes736d567Make most fields default87f9752Use default audience as Pocket ID AppURL4236fd7Lintcebd618generalized test util newDatabaseForTest01bed5dscaffolding tests9efda6eCreateClient/UpdateClient can now set credentialsd0a175aAdd testsd9b3dc1More tests📊 Changes
38 files changed (+1460 additions, -289 deletions)
View changed files
📝
.gitignore(+1 -0)📝
backend/go.mod(+5 -5)📝
backend/go.sum(+10 -10)📝
backend/internal/bootstrap/e2etest_router_bootstrap.go(+8 -1)📝
backend/internal/bootstrap/services_bootstrap.go(+9 -5)📝
backend/internal/common/errors.go(+5 -0)📝
backend/internal/controller/e2etest_controller.go(+50 -5)📝
backend/internal/controller/oidc_controller.go(+9 -7)📝
backend/internal/dto/dto_mapper.go(+53 -0)📝
backend/internal/dto/oidc_dto.go(+31 -16)📝
backend/internal/model/oidc.go(+44 -2)📝
backend/internal/service/app_config_service.go(+3 -3)📝
backend/internal/service/app_config_service_test.go(+14 -66)📝
backend/internal/service/e2etest_service.go(+129 -18)📝
backend/internal/service/jwt_service.go(+2 -55)📝
backend/internal/service/jwt_service_test.go(+2 -1)📝
backend/internal/service/oidc_service.go(+225 -41)➕
backend/internal/service/oidc_service_test.go(+365 -0)➕
backend/internal/service/testutils_test.go(+97 -0)➕
backend/internal/utils/jwk_util.go(+69 -0)...and 18 more files
📄 Description
Fixes #361
TLDR
Goals
Full discussion is in #361, but to recap...
We want to enable confidential clients (OAuth2 applications) to perform a token exchange without having to use a client secret, because client secrets are long-lived shared secrets and are not the best solution for security.
/api/oidc/tokenendpoint, normally they include a client ID and client secret. With this change, instead of a client secret they can includeclient_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer(this is a constant defined in the RFC) and aclient_assertion=...containing a JWT signed by an external identity server, which is issued to the application to identify itselfReferences
How this works
Users should be able to add one or more federated identities for each app in Pocket ID. For each federated identity they'll need to provide:
issfor the external identity service<iss>/.well-known/jwks.jsonThen, OAuth2 apps will be able to present as
client_assertionJWTs that are signed by the issuer above, and which have the subject and audience configured as per above.How you can test this
Credentials:
https://alessandrosegala.blob.core.windows.net/https://alessandrosegala.blob.core.windows.net/$root/jwks.jsonTo test it:
api://PocketIDTokenExchangefor audience and123456abcdeffor subject.Use one of these values for
CLIENT_ASSERTION:🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.