The Corbado Java SDK provides convenient access to the Corbado Backend API from applications written in the Java language.
🚀 Getting started | 🛠️ Services | 📚 Advanced | 💬 Support & Feedback
- Java 8 or later
You can find the latest SDK version at central repository
Add this dependency to your project's build file:
implementation "com.corbado:corbado-java:1.0.4"
Add this dependency to your project's POM:
<dependency>
<groupId>com.corbado</groupId>
<artifactId>corbado-java</artifactId>
<version>1.0.4</version>
</dependency>
To create a Corbado Java SDK instance you need to provide your Project ID
and API secret
which can be found at the Developer Panel.
final Config config = new Config(projectId, apiSecret);
CorbadoSdk sdk = new CorbadoSDK(config);
A list of examples can be found in the integration tests here.
The Corbado Java SDK provides the following services:
sessions
for managing sessions (example spring boot application)users
for managing users (examples)identifiers
for managing identifiers (examples)
To use a specific service, such as users
, invoke it as shown below:
UserService users = sdk.getUsers();
The Corbado Java SDK raises exceptions for all errors except those that occur in the session service during token validation (See example below on how to catch those errors). The following exceptions are thrown:
CorbadoServerException
for server errors (server side)StandardException
for everything else (client side)JWTVerificationException
and its subclasses andJwkException
in session service for JWT/JWK errors.
If the Backend API returns a HTTP status code other than 200, the Corbado Java SDK throws a CorbadoServerException
. The CorbadoServerException
class parses the server response to access all important data. One of the test cases:
UserService users = sdk.getUsers();
final UserEntity user = TestUtils.createUser();
users.delete(user.getUserID());
final CorbadoServerException e =
assertThrows(
CorbadoServerException.class,
() -> {
final UserEntity ret = users.get(user.getUserID());
});
assertNotNull(e);
assertEquals(400, e.getHttpStatusCode());
assertEquals("does not exist", e.getValidationMessages().get(0).getMessage());
assertEquals("userID", e.getValidationMessages().get(0).getField());
Take a look at the CorbadoServerException
class, if you need get more information out of exception.
If you encounter any bugs or have suggestions, please open an issue.
Join our Slack channel to discuss questions or ideas with the Corbado team and other developers.
You can also reach out to us via email at [email protected].
Please report suspected security vulnerabilities in private to [email protected]. Please do NOT create publicly viewable issues for suspected security vulnerabilities.