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.9"Add this dependency to your project's POM:
<dependency>
<groupId>com.corbado</groupId>
<artifactId>corbado-java</artifactId>
<version>1.0.9</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.
//Example initialization of Config class with builder (preferred).
Config config = null;
if (StringUtils.isEmpty(backendApi)) {
config = Config.builder().apiSecret(apiSecret).projectId(projectId).build();
} else {
config =
Config.builder().apiSecret(apiSecret).projectId(projectId).backendApi(backendApi).build();
}
//Alternative initialization with 'new'.
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:
sessionsfor managing sessions (example spring boot application)usersfor managing users (examples)identifiersfor 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:
CorbadoServerExceptionfor server errors (server side)StandardExceptionfor everything else (client side)JWTVerificationExceptionand its subclasses andJwkExceptionin 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 CorbadoServerExceptionclass 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 vincent.delitz@corbado.com.
Please report suspected security vulnerabilities in private to security@corbado.com. Please do NOT create publicly viewable issues for suspected security vulnerabilities.