Skip to content

corbado/corbado-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Repo Cover

Corbado Java SDK

License documentation Slack

The Corbado Java SDK provides convenient access to the Corbado Backend API from applications written in the Java language.

⚠️ 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.

🚀 Getting started | 🛠️ Services | 📚 Advanced | 💬 Support & Feedback

🚀 Getting started

Requirements

  • Java 8 or later

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.4"

Maven users

Add this dependency to your project's POM:

<dependency>
  <groupId>com.corbado</groupId>
  <artifactId>corbado-java</artifactId>
  <version>1.0.4</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.

 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.

🛠️ 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();

📚 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.

💬 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.

Slack

Email

You can also reach out to us via email at [email protected].

Vulnerability reporting

Please report suspected security vulnerabilities in private to [email protected]. Please do NOT create publicly viewable issues for suspected security vulnerabilities.