Add public getAccessToken() methods to expose OAuth2 tokens from client credentials#214
Draft
Add public getAccessToken() methods to expose OAuth2 tokens from client credentials#214
Conversation
Co-authored-by: aaguiarz <1636576+aaguiarz@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Provide a way to obtain the access token retrieved from the client credentials endpoint, so it's possible to include it in my API calls
Add public getAccessToken() methods to expose OAuth2 tokens from client credentials
Aug 22, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds public getAccessToken() methods to both OpenFgaApi and OpenFgaClient classes to expose OAuth2 tokens obtained from client credentials authentication. This allows users to retrieve and reuse the same token for API calls to other services.
- Adds
getAccessToken()method to both API and client classes with CLIENT_CREDENTIALS validation - Returns
CompletableFuture<String>for asynchronous token retrieval - Includes comprehensive test coverage for success and error scenarios
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/main/java/dev/openfga/sdk/api/OpenFgaApi.java | Implements core getAccessToken() method with CLIENT_CREDENTIALS validation |
| src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java | Adds wrapper getAccessToken() method that delegates to the API class |
| src/test/java/dev/openfga/sdk/api/OpenFgaApiTest.java | Tests for API class including success, API token error, and no credentials scenarios |
| src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java | Tests for client class covering success and API token error cases |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
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.
This PR adds public
getAccessToken()methods to bothOpenFgaApiandOpenFgaClientto allow users to retrieve the OAuth2 access token obtained from the client credentials endpoint. This enables users to include the same token in their own API calls to other services.Problem
Previously, the SDK internally managed OAuth2 tokens but provided no way for users to access them. Users who needed to make API calls to other services that accept the same OAuth2 token had no way to retrieve it from the SDK.
Solution
Added public
getAccessToken()methods to both client classes:Key Features
CLIENT_CREDENTIALSauthentication, throwingIllegalStateExceptionfor other auth methodsCompletableFuture<String>for non-blocking token retrievalOpenFgaApiandOpenFgaClientprovide the same functionalityImplementation Details
The implementation is minimal and surgical:
Testing
Added comprehensive test coverage including:
Use Cases
This enables users to:
The changes are fully backward compatible with zero breaking changes to existing functionality.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
invalid-hostname-that-does-not-exist.local/usr/lib/jvm/temurin-17-jdk-amd64/bin/java -Dorg.gradle.internal.worker.tmpdir=/home/REDACTED/work/java-sdk/java-sdk/build/tmp/test/work -Dorg.gradle.native=false -javaagent:/home/REDACTED/work/java-sdk/java-sdk/build/tmp/.cache/expanded/zip_0bd0851504e6286cb5fc6f37a81e25cc/jacocoagent.jar=destfile=build/jacoco/test.exec,append=true,inclnolocationclasses=false,dumponexit=true,output=file,jmx=false @/home/REDACTED/.gradle/.tmp/gradle-worker-classpath15454675414686019558txt -Xmx512m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -ea worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Test Executor 1'(dns block)/usr/lib/jvm/temurin-17-jdk-amd64/bin/java -Dorg.gradle.internal.worker.tmpdir=/home/REDACTED/work/java-sdk/java-sdk/build/tmp/test/work -Dorg.gradle.native=false -javaagent:/home/REDACTED/work/java-sdk/java-sdk/build/tmp/.cache/expanded/zip_0bd0851504e6286cb5fc6f37a81e25cc/jacocoagent.jar=destfile=build/jacoco/test.exec,append=true,inclnolocationclasses=false,dumponexit=true,output=file,jmx=false @/home/REDACTED/.gradle/.tmp/gradle-worker-classpath10115047697685244126txt -Xmx512m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -ea worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Test Executor 5'(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.