Repository navigation
feat(thirdparty): Spring Security oauth2Client for the Data Custodian authorization (#146) - #275
Merged
Merged
Conversation
… authorization (#146) The Third Party's customer flow now uses Spring Security 7 oauth2Client instead of oauth2Login: the TP customer stays signed in to the TP (form login) while authorizing it at the Data Custodian, and the tokens are kept for that customer. - Tokens are stored in the ESPI authorizations table through a new OAuth2AuthorizedClientService (EspiAuthorizationOAuth2AuthorizedClientService), with the REQ.21 token-response URIs (resourceURI, authorizationURI, customerResourceURI) captured from the token response. A refresh that does not repeat them keeps the stored URIs. - Flyway V6 adds authorizations.client_registration_id (MySQL, PostgreSQL, H2). - Only a signed-in TP customer (ROLE_USER) may start an authorization_code registration; anonymous visitors go to /login, the TP administrator gets 403. - datacustodian-admin is now the client_credentials registration for the TP's client access token (FB=34_35). The TP administrator obtains it on the admin page, which shows its scope, expiry, a token prefix and the authorizationURI, resourceURI (energy usage Bulk) and customerResourceURI (Customer PII Bulk) once the AS returns them (#202). - The TP home page lists the customer's authorizations. - PKCE is off in the TP until the AS carries code_challenge through the Data Custodian delegation (#274). - Removed the legacy /oauth/callback controller, the oauth2Login user-info settings and the openid/profile scopes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ore (#146) - Obtaining a new client access token no longer revokes the current one first: the new token is requested directly and replaces the stored one only once issued and saved. A refusal, an unreachable AS or a persistence error (DataAccessException) shows client_token_error and keeps the token in use. - Authorization rows get a deterministic UUID5 id from the registration and customer (EspiIdGeneratorService.generateEntityId) instead of a random v4 id, so racing saves cannot insert a duplicate row. - The callback page reports success only for authorization_code registrations; the TP's client access token never counts as a customer's authorization. - The ESPI token-response URIs are handed to the store through an in-memory map keyed by access token (entries expire after 5 minutes) instead of request attributes, so a token refreshed outside a web request keeps them. - The home page loads the customer's authorizations with one derived query. - Removed the unreachable "session ended" message from home.html; the test now checks that a callback after the session ended requires sign-in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…low (#146) - A visitor who starts a Data Custodian authorization signed out no longer consents twice: starting an authorization clears the request saved before sign-in, which OAuth2AuthorizationCodeGrantFilter would otherwise redirect to after the code exchange instead of the callback. - Obtaining a client access token shows client_token_error for a missing datacustodian-admin registration and for any failure while obtaining or saving the token; the token already held stays in use. - EspiTokenResponseParameters is a Spring bean shared by the token-response clients and the token store instead of static state; entries never taken expire on both put and take. - The token store gets EspiIdGeneratorService injected, and the expiry is read with AuthorizationEntity.getExpirationInstant() in both places. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #146.
Summary
The Third Party's customer flow moves from
oauth2Loginto Spring Security 7oauth2Client. The TP customer signs in to the TP (form login, #249) and stays signed in while authorizing the TP at the Data Custodian (TP → AS → DC consent → AS → TP callback). The tokens are kept for that customer.Token storage
EspiAuthorizationOAuth2AuthorizedClientServicestores authorized clients in the ESPIauthorizationstable.resourceURI,authorizationURIandcustomerResourceURIare captured from the token response byEspiTokenResponseParametersand stored with the token. A refresh response that does not repeat them keeps the stored URIs.V6__Add_authorization_client_registration_id.sql(shared, all vendors) addsauthorizations.client_registration_id.Who may start what
TpCustomerAuthorizationRequestResolverhandles/oauth2/authorization/{registrationId}:ROLE_USER) may start an authorization_code registration./loginand back afterwards; the TP administrator gets 403.The callback (
/login/oauth2/code/{registrationId}) returns the customer to/?authorized, or/?authorization_erroron a refusal or a forged callback.Client access token (
FB=34_35)datacustodian-adminis now the client_credentials registration for the TP's client access token.authorizationURI,resourceURI(energy usage Bulk) andcustomerResourceURI(Customer PII Bulk), once the AS returns them (ESPI token-response URIs: FB_51 gating, re-provisioning on refresh, missing URIs for client_credentials tokens #202 item 3).UI
Removed
/oauth/callbackcontroller (ModernAuthorizationController) and its test./oauth2/authorize/admin,/oauth2/authorize/client/{id}and/oauth2/authorize/success.openid/profilescopes (OIDC was removed in Strip unused OIDC/JWK/JWT from auth-server (ESPI is opaque-only) #134).PKCE is off in the TP for now (#274)
/oauth2/authorizeafter the DC's consent withoutcode_challenge, so the code exchange failed withinvalid_grant. The AS also registersthird_partywithrequireProofKey(false)(PR D: Phase 2.0 integration test — auth-code flow + introspection + token-response augmentation end-to-end (closes #122 Step 6) #148).code_challengethrough the delegation, after which the TP can send PKCE again.Still open (AS side)
customerResourceURIis gated on FB 54–62 instead of FB_51.FB=34_35client access token has noauthorizationURI, energy usage BulkresourceURIor Customer PII BulkcustomerResourceURI.Tests
DataCustodianAuthorizationTest(new, 9 tests) runs against a stub token endpoint:/login.Suites (WSL, with Docker):
The Data Custodian and Third Party suites ran without
AboutControllerTest. That test fails on a JDK whosejava.versionis exactly25: the About page contains the Bootstrap classw-25. This branch doesn't cause it (#277).Manual end-to-end test (
localprofile):?authorized, still signed in.FB=4_5_15;IntervalDuration=3600;BlockDuration=monthly;HistoryLength=13withresourceURIandauthorizationURI.?authorization_error.FB=34_35, ACTIVE, six-hour expiry, no URIs yet (ESPI token-response URIs: FB_51 gating, re-provisioning on refresh, missing URIs for client_credentials tokens #202).docs/LOCAL_TESTING.mdhas a new "Customer flow (TP → AS → DC → TP)" section and updated logins and known limitations.Review fixes (17cbb15)
EspiIdGeneratorService.generateEntityId). Racing saves cannot insert a duplicate row, and ids follow the project's UUID5 rule.findAllByRetailCustomer_UsernameAndClientRegistrationIdIsNotNullOrderByUpdatedDesc).home.html: the unreachable "session ended" message is removed. A callback after the TP session ended now goes to/loginfirst, and a test checks that.DataCustodianAuthorizationTest: a refused request keeps the current client token; the callback page ignores the client access token; a stored row's id is version 5.EspiTokenResponseParametersTest: the URIs are handed over on another thread, and only once.Second review fixes (3067f5c)
OAuth2AuthorizationCodeGrantFilterwould otherwise redirect to after the code exchange.datacustodian-adminregistration, and any failure while obtaining or saving the token, showclient_token_error. The token already held stays in use.EspiTokenResponseParameters: now a Spring bean shared by the token-response clients and the token store, instead of static state. Entries never taken expire on both put and take.EspiIdGeneratorServiceis injected, and the expiry is read withAuthorizationEntity.getExpirationInstant().?authorizedwith one round trip (it fails without the fix).CustodianHomeControllerClientTokenTest, and expiry inEspiTokenResponseParametersTest.🤖 Generated with Claude Code