Creating application using Java SDK

Hello people, I tried creating an app using the below piece of code:

public class App {

public static void main(String ...args) {
    ClientCredentials clientCredentials = new TokenClientCredentials("004_0lRs-F3WXP9xqAD20feFJIXzv77ZstGoIV_m0V");
    Client client = Clients.builder().setOrgUrl("https://dev-365402.okta.com").setClientCredentials(clientCredentials).build();

    Application application = client.createApplication(client.instantiate(AutoLoginApplication.class)
                .setLabel("ss")
                .setAccessibility(client.instantiate(ApplicationAccessibility.class)
                    .setErrorRedirectUrl("www.help.com")
                    .setLoginRedirectUrl("www.app.com"))
                .setVisibility(client.instantiate(ApplicationVisibility.class)
                    .setHide(client.instantiate(ApplicationVisibilityHide.class)
                        .setIOS(true)
                        .setWeb(false)))
                .setLicensing(client.instantiate(ApplicationLicensing.class)
                    .setSeatCount(1))
    );
}

}

But then during execution, I get Exception : in thread “main” com.okta.sdk.resource.ResourceException: HTTP 500, Okta E0000009 (Internal Server Error), ErrorId oaeUCHlkhO4SCOfWyXKG9wqWw.

Please advise

Hi @jeyadev

To better understand the use-case, what type of application do you want to create through the SDK?

Hi @dragos

Thank you for the continued support across the questions posted.
I want to create a new application with the sign-on method as OpenID Connect (OAUTH2 client app).
However, the sample provided above was one of the many attempts by me to get any app created via SDK.

Hi @jeyadev

Here is an example to create a native OIDC application

        Application oidc = client.createApplication(client.instantiate(OpenIdConnectApplication.class)
                .setLabel("Test OIDC app")
                .setSettings(
                        client.instantiate(OpenIdConnectApplicationSettings.class)
                            .setOAuthClient(client.instantiate(OpenIdConnectApplicationSettingsClient.class)
                                    .setRedirectUris(Arrays.asList("https://google.com"))
                                    .setResponseTypes(Arrays.asList(OAuthResponseType.TOKEN, OAuthResponseType.CODE))
                                    .setGrantTypes(Arrays.asList(OAuthGrantType.IMPLICIT, OAuthGrantType.AUTHORIZATION_CODE))
                                    .setApplicationType(OpenIdConnectApplicationType.NATIVE)
                            )
                )
                .setCredentials(
                        client.instantiate(OAuthApplicationCredentials.class)
                            .setOAuthClient(client.instantiate(ApplicationCredentialsOAuthClient.class)
                                    .setClientId("client-id-here")
                                    .setClientSecret("client-secret-here")
                                    .setAutoKeyRotation(true)
                                    .setTokenEndpointAuthMethod(OAuthEndpointAuthenticationMethod.NONE)
                            )
                ).setVisibility(client.instantiate(ApplicationVisibility.class)
                        .setHide(client.instantiate(ApplicationVisibilityHide.class)
                                .setIOS(true)
                                .setWeb(false)))
        );

@dragos, awesome!! Thanks a ton!

Meanwhile one last question,

Say we have an error,

com.okta.sdk.resource.ResourceException: HTTP 400, Okta E0000001 (Api validation failed: App Instance), ErrorId oaeKQ3LhZuTSeSDwH-2MJjyjw

Also in some cases, we receive an error stating the number of issues, is there a possibility to understand more about the error log? Thanks again.

Hi @jeyadev

It depends on the response, it can be either an issue with the JSON generated by the SDK or another issue. If you don’t have additional message in the response, please feel free to send an email to developers@okta.com and one of our Developer Support Engineers can assist you with additional details regarding the error registered in the logs.

1 Like