Corbado Java SDK
The Corbado Java SDK provides convenient access to the Corbado Backend API from applications written in the Java language.
:warning: The Corbado Java SDK is commonly referred to as a private client, specifically designed for usage within closed backend applications. This particular SDK should exclusively be utilized in such environments, as it is crucial to ensure that the API secret remains strictly confidential and is never shared.
:rocket: Getting started | :hammer_and_wrench: Services | :books: Advanced | :speech_balloon: Support & Feedback
:rocket: Getting started
Requirements
Installation
You can find the latest SDK version at central repository
Gradle users
Add this dependency to your project's build file:
implementation "com.corbado:corbado-java:1.0.9"
Maven users
Add this dependency to your project's POM:
<dependency>
<groupId>com.corbado</groupId>
<artifactId>corbado-java</artifactId>
<version>1.0.9</version>
</dependency>
Usage
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);
Examples
A list of examples can be found in the integration tests here.
:hammer_and_wrench: Services
The Corbado Java SDK provides the following services:
To use a specific service, such as users, invoke it as shown below:
UserService users = sdk.getUsers();
:books: Advanced
Error handling
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 and JwkException 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 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.
:speech_balloon: Support & Feedback
Report an issue
If you encounter any bugs or have suggestions, please open an issue.
Slack channel
Join our Slack channel to discuss questions or ideas with the Corbado team and other developers.
Email
You can also reach out to us via email at vincent.delitz@corbado.com.
Vulnerability reporting
Please report suspected security vulnerabilities in private to security@corbado.com. Please do NOT create publicly viewable issues for suspected security vulnerabilities.