Files
clerk-sdk-java/docs/sdks/oauthapplications/README.md
2024-06-13 13:51:50 -04:00

21 KiB
Raw Blame History

OAuthApplications

(oAuthApplications())

Available Operations

  • list - Get a list of OAuth applications for an instance
  • create - Create an OAuth application
  • get - Retrieve an OAuth application by ID
  • updateApplication - Update an OAuth application
  • delete - Delete an OAuth application
  • rotateSecret - Rotate the client secret of the given OAuth application

list

This request returns the list of OAuth applications for an instance. Results can be paginated using the optional limit and offset query parameters. The OAuth applications are ordered by descending creation date. Most recent OAuth applications will be returned first.

Example Usage

package hello.world;

import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.components.*;
import com.clerk.backend_api.models.components.Security;
import com.clerk.backend_api.models.operations.*;
import com.clerk.backend_api.utils.EventStream;
import java.math.BigDecimal;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;

public class Application {

    public static void main(String[] args) throws Exception {
        try {
            Clerk sdk = Clerk.builder()
                .bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
                .build();

            ListOAuthApplicationsResponse res = sdk.oAuthApplications().list()
                .limit(10L)
                .offset(0L)
                .call();

            while (true) {
                if (res.oAuthApplications().isPresent()) {
                    // handle response
                    Optional<ListOAuthApplicationsResponse> nextRes = res.next();
                    if (nextRes.isPresent()) {
                        res = nextRes.get();
                    } else {
                        break;
                    }
                }
            }
        } catch (com.clerk.backend_api.models.errors.ClerkErrors e) {
            // handle exception
            throw e;
        } catch (com.clerk.backend_api.models.errors.SDKError e) {
            // handle exception
            throw e;
        } catch (Exception e) {
            // handle exception
            throw e;
        }
    }
}

Parameters

Parameter Type Required Description
limit Optional<? extends Long> Applies a limit to the number of results returned.
Can be used for paginating the results together with offset.
offset Optional<? extends Long> Skip the first offset results when paginating.
Needs to be an integer greater or equal to zero.
To be used in conjunction with limit.

Response

Optional<? extends com.clerk.backend_api.models.operations.ListOAuthApplicationsResponse>

Errors

Error Object Status Code Content Type
models/errors/ClerkErrors 400,403,422 application/json
models/errors/SDKError 4xx-5xx /

create

Creates a new OAuth application with the given name and callback URL for an instance. The callback URL must be a valid url. All URL schemes are allowed such as http://, https://, myapp://, etc...

Example Usage

package hello.world;

import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.components.*;
import com.clerk.backend_api.models.components.Security;
import com.clerk.backend_api.models.operations.*;
import com.clerk.backend_api.utils.EventStream;
import java.math.BigDecimal;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;

public class Application {

    public static void main(String[] args) throws Exception {
        try {
            Clerk sdk = Clerk.builder()
                .bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
                .build();

            CreateOAuthApplicationRequestBody req = CreateOAuthApplicationRequestBody.builder()
                .name("<value>")
                .callbackUrl("<value>")
                .scopes("profile email public_metadata")
                .build();

            CreateOAuthApplicationResponse res = sdk.oAuthApplications().create()
                .request(req)
                .call();

            if (res.oAuthApplicationWithSecret().isPresent()) {
                // handle response
            }
        } catch (com.clerk.backend_api.models.errors.ClerkErrors e) {
            // handle exception
            throw e;
        } catch (com.clerk.backend_api.models.errors.SDKError e) {
            // handle exception
            throw e;
        } catch (Exception e) {
            // handle exception
            throw e;
        }
    }
}

Parameters

Parameter Type Required Description
request com.clerk.backend_api.models.operations.CreateOAuthApplicationRequestBody ✔️ The request object to use for the request.

Response

Optional<? extends com.clerk.backend_api.models.operations.CreateOAuthApplicationResponse>

Errors

Error Object Status Code Content Type
models/errors/ClerkErrors 400,403,422 application/json
models/errors/SDKError 4xx-5xx /

get

Fetches the OAuth application whose ID matches the provided id in the path.

Example Usage

package hello.world;

import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.components.*;
import com.clerk.backend_api.models.components.Security;
import com.clerk.backend_api.models.operations.*;
import com.clerk.backend_api.utils.EventStream;
import java.math.BigDecimal;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;

public class Application {

    public static void main(String[] args) throws Exception {
        try {
            Clerk sdk = Clerk.builder()
                .bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
                .build();

            GetOAuthApplicationResponse res = sdk.oAuthApplications().get()
                .oauthApplicationId("<value>")
                .call();

            if (res.oAuthApplication().isPresent()) {
                // handle response
            }
        } catch (com.clerk.backend_api.models.errors.ClerkErrors e) {
            // handle exception
            throw e;
        } catch (com.clerk.backend_api.models.errors.SDKError e) {
            // handle exception
            throw e;
        } catch (Exception e) {
            // handle exception
            throw e;
        }
    }
}

Parameters

Parameter Type Required Description
oauthApplicationId String ✔️ The ID of the OAuth application

Response

Optional<? extends com.clerk.backend_api.models.operations.GetOAuthApplicationResponse>

Errors

Error Object Status Code Content Type
models/errors/ClerkErrors 403,404 application/json
models/errors/SDKError 4xx-5xx /

updateApplication

Updates an existing OAuth application

Example Usage

package hello.world;

import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.components.*;
import com.clerk.backend_api.models.components.Security;
import com.clerk.backend_api.models.operations.*;
import com.clerk.backend_api.utils.EventStream;
import java.math.BigDecimal;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;

public class Application {

    public static void main(String[] args) throws Exception {
        try {
            Clerk sdk = Clerk.builder()
                .bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
                .build();

            UpdateOAuthApplicationResponse res = sdk.oAuthApplications().updateApplication()
                .oauthApplicationId("<value>")
                .requestBody(UpdateOAuthApplicationRequestBody.builder()
                    .scopes("profile email public_metadata private_metadata")
                    .build())
                .call();

            if (res.oAuthApplication().isPresent()) {
                // handle response
            }
        } catch (com.clerk.backend_api.models.errors.ClerkErrors e) {
            // handle exception
            throw e;
        } catch (com.clerk.backend_api.models.errors.SDKError e) {
            // handle exception
            throw e;
        } catch (Exception e) {
            // handle exception
            throw e;
        }
    }
}

Parameters

Parameter Type Required Description
oauthApplicationId String ✔️ The ID of the OAuth application to update
requestBody com.clerk.backend_api.models.operations.UpdateOAuthApplicationRequestBody ✔️ N/A

Response

Optional<? extends com.clerk.backend_api.models.operations.UpdateOAuthApplicationResponse>

Errors

Error Object Status Code Content Type
models/errors/ClerkErrors 403,404,422 application/json
models/errors/SDKError 4xx-5xx /

delete

Deletes the given OAuth application. This is not reversible.

Example Usage

package hello.world;

import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.components.*;
import com.clerk.backend_api.models.components.Security;
import com.clerk.backend_api.models.operations.*;
import com.clerk.backend_api.utils.EventStream;
import java.math.BigDecimal;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;

public class Application {

    public static void main(String[] args) throws Exception {
        try {
            Clerk sdk = Clerk.builder()
                .bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
                .build();

            DeleteOAuthApplicationResponse res = sdk.oAuthApplications().delete()
                .oauthApplicationId("<value>")
                .call();

            if (res.deletedObject().isPresent()) {
                // handle response
            }
        } catch (com.clerk.backend_api.models.errors.ClerkErrors e) {
            // handle exception
            throw e;
        } catch (com.clerk.backend_api.models.errors.SDKError e) {
            // handle exception
            throw e;
        } catch (Exception e) {
            // handle exception
            throw e;
        }
    }
}

Parameters

Parameter Type Required Description
oauthApplicationId String ✔️ The ID of the OAuth application to delete

Response

Optional<? extends com.clerk.backend_api.models.operations.DeleteOAuthApplicationResponse>

Errors

Error Object Status Code Content Type
models/errors/ClerkErrors 403,404 application/json
models/errors/SDKError 4xx-5xx /

rotateSecret

Rotates the OAuth application's client secret. When the client secret is rotated, make sure to update it in authorized OAuth clients.

Example Usage

package hello.world;

import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.components.*;
import com.clerk.backend_api.models.components.Security;
import com.clerk.backend_api.models.operations.*;
import com.clerk.backend_api.utils.EventStream;
import java.math.BigDecimal;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;

public class Application {

    public static void main(String[] args) throws Exception {
        try {
            Clerk sdk = Clerk.builder()
                .bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
                .build();

            RotateOAuthApplicationSecretResponse res = sdk.oAuthApplications().rotateSecret()
                .oauthApplicationId("<value>")
                .call();

            if (res.oAuthApplicationWithSecret().isPresent()) {
                // handle response
            }
        } catch (com.clerk.backend_api.models.errors.ClerkErrors e) {
            // handle exception
            throw e;
        } catch (com.clerk.backend_api.models.errors.SDKError e) {
            // handle exception
            throw e;
        } catch (Exception e) {
            // handle exception
            throw e;
        }
    }
}

Parameters

Parameter Type Required Description
oauthApplicationId String ✔️ The ID of the OAuth application for which to rotate the client secret

Response

Optional<? extends com.clerk.backend_api.models.operations.RotateOAuthApplicationSecretResponse>

Errors

Error Object Status Code Content Type
models/errors/ClerkErrors 403,404 application/json
models/errors/SDKError 4xx-5xx /