Skip to content

feat: add HTTP URL-connection support for Authlete API v3 #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jul 18, 2025

Conversation

meysam
Copy link
Contributor

@meysam meysam commented Jun 5, 2025

References

  • [ENG-3828]

Context / Summary

Until now this library only offered JAX-RS and Jakarta-based clients for Authlete API v3, which adds extra dependencies and inconsistent error-handling. This PR introduces a pure-Java HttpURLConnection-based client for v3 and refactors the existing v2 client to share all connection, serialization, timeout, and DPoP logic in a new AuthleteApiBasicImpl base class. Consumers can now switch between v2 and v3 clients simply by changing apiVersion in their configuration, with zero behavioral change to v2 and full support for every v3 endpoint.

Description / Changes Made

  • AuthleteApiBasicImpl
    • Centralizes HTTP connection setup (timeouts, headers, URL builder)
    • Unifies JSON (de)serialization via Gson/Nimbus and DPoP JWT signing
    • Provides consistent error-handling and retry hooks
  • AuthleteApiImpl (v2)
    • Refactored to extend AuthleteApiBasicImpl
    • Replaced dozens of nearly-identical callService*Api methods with a small hierarchy of ApiCaller helper classes (ServiceGetApiCaller, ServicePostApiCaller, ServiceDeleteApiCaller) and a single executeApiCall(…) entry point
    • Reduced boilerplate by ~1,500 lines while preserving full v2 coverage
  • AuthleteApiImplV3
    • Implements every v3 endpoint (authorization, token, introspection, device, backchannel, VCI, SSO, JWKS, federation, batch ops, etc.) on top of AuthleteApiBasicImpl
    • Uses PostApiCaller, GetApiCaller or DeleteApiCaller for each endpoint for consistent invocation and error propagation
  • RequestableScopes
    • New model class for /api/client/extension/requestable_scopes/* APIs (GET, POST, DELETE)
    • Supported in both v2 and v3 clients
  • AuthleteApiFactory
    • Updated to include AuthleteApiImplV3 in the list of known v3 implementations
  • pom.xml
    • Bumped nimbus-jose-jwt to 9.31 (property nimbus.version) to support latest JOSE/JWT features required for DPoP

Schema Changes

None

Breaking Changes

None. All existing v2 behavior is preserved; v3 is opt-in via AuthleteConfiguration.setApiVersion("V3").

Testing Instructions

  1. Run mvn clean verify to exercise existing unit tests.
  2. In a sample client or integration test, configure:
    authlete.apiVersion=V3
    authlete.serviceAccessToken=<valid-v3-token>
    authlete.baseUrl=https://api.authlete.com
  3. Execute core flows (authorizationtokenintrospectionuserinfo) and verify the HttpURLConnection-based client works end-to-end.
  4. Switch back to apiVersion=V2 and rerun the same flows to confirm no regressions in the v2 client.
  5. (Optional) Test advanced v3 endpoints: device authorization, backchannel flows, VCI batch operations, federation metadata.

Screenshots / Snippets

// Example: creating the v3 client and issuing an authorization request
AuthleteConfiguration config = new AuthleteConfiguration()
    .setBaseUrl("https://api.authlete.com")
    .setApiVersion("V3")
    .setServiceAccessToken("eyJhbGciOiJI…")    // a valid v3 access token
    .setDpopKey(dpopJwkJson);                  // optional DPoP JWK

AuthleteApi api = AuthleteApiFactory.create(config);

AuthorizationResponse authzResponse = api.authorization(
    new AuthorizationRequest()
        .setClientId("0cd7e123-…")
        .setScopes(new String[]{"openid","email"})
        .setSubject("user123"),
    new Options().setWantContent(true)
);
System.out.println(authzResponse.getTicket());

Added Tests?

No new tests in this PR.

Related PRs

None


meysam added 3 commits June 5, 2025 05:45
- Introduce AuthleteApiImplV3 using HttpURLConnection for API v3
- Introduce AuthleteApiBasicImpl to leverage URLConnection
- Update AuthleteApiFactory to select v3 implementation
- Migrate and streamline existing AuthleteApiImpl methods to align with v3
- Enhance RequestableScopes enum for new scope handling
- Bump dependencies in pom.xml
…ception

- Add deleteApiResponse helper in AuthleteApiBasicImpl to catch HTTP 403 and parse its JSON payload into an ApiResponse
- Refactor communicate() to only throw on HTTP errors when responseClass != null (so DELETE calls return error bodies rather than exceptions)
- Override deleteClient and deleteService in AuthleteApiImplV3 to use deleteApiResponse for delete operations
- Remove the special-case 403 block from communicate(), consolidating error handling through the new helper
@meysam meysam marked this pull request as ready for review June 11, 2025 02:15
@meysam meysam self-assigned this Jun 11, 2025
meysam added 2 commits June 13, 2025 05:19
- Organize imports in AuthleteApiBasicImpl

- Fix method declaration spacing

- Update copyright years to 2025

- Add newlines for better readability
- Remove callGetApiNullFor404 and callGetApiParse404 methods
since their functionality is already covered by callApiWithNotFoundHandling.
This simplifies the API by removing duplicate methods and encourages direct
use of the more flexible callApiWithNotFoundHandling method.
@meysam meysam requested a review from hidebike712 June 25, 2025 21:12
meysam added 3 commits June 30, 2025 10:43
- Replace star imports with explicit imports in AuthleteApiImpl and AuthleteApiImplV3
- Fix local variable naming conventions (value_ → descriptive names) in MapUtils
- Correct control flow issues: missing braces in Utils.java and fall-through in CLI.java
- Fix whitespace after comma violations across assurance package and other files
- Add Checkstyle and SpotBugs configuration with custom rules
- Update README.md with code quality tools documentation
- Configure maven-checkstyle-plugin and spotbugs-maven-plugin in pom.xml
- Update SpotBugs Maven plugin to version 4.9.3.2
- Move reporting configuration from maven-site-plugin to proper <reporting> section
- Fix regex syntax error in Helper.java (remove space in quantifier {1, } → {1,})
- Add proper <reporting> section with maven-javadoc-plugin, maven-checkstyle-plugin, and spotbugs-maven-plugin
- Configure SpotBugs to use XML filter files (mvn-config/spotbugs/spotbugs-include.xml and spotbugs-exclude.xml)
- Replace hypothetical API result codes with empty ApiResponse objects
@meysam meysam requested a review from hidebike712 June 30, 2025 21:52
@hidebike712
Copy link
Member

Thanks for your changes. I've reviewed the code. Would be great if can chenck them and an unresolved discussion.

@hidebike712
Copy link
Member

Thank you! I think it looks good.

@meysam meysam requested review from shaikathaque and removed request for shaikathaque July 6, 2025 21:06
@zamd
Copy link
Contributor

zamd commented Jul 18, 2025

I’ve tested the authorization code flow and introspection—it’s working fine.

@zamd zamd merged commit d56593c into master Jul 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants