Skip to content

Commit

Permalink
Merge pull request #26 from oktadeveloper/update-reg-flow
Browse files Browse the repository at this point in the history
Update reg flow
  • Loading branch information
dogeared authored Aug 6, 2020
2 parents 8b5607a + c04f937 commit e44a470
Show file tree
Hide file tree
Showing 44 changed files with 1,299 additions and 345 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ target/
velocity.log
.idea
*.iml
.DS_Store
1 change: 0 additions & 1 deletion .java-version

This file was deleted.

3 changes: 3 additions & 0 deletions .sdkmanrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
java=20.0.0.r11-grl
22 changes: 8 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,17 @@ echo `. ~/okta.bash` >> ~/.bash_profile

For more details on using bash completion see the [Picocli documentation](https://picocli.info/autocomplete.html#_installing_completion_scripts_permanently_in_bashzsh).

## Building / Contributing
## Contribute

You'll need to use the [GraalVM]() to build this project. That's what supports the native build.
The easiest way to build the project is to use [sdkman]().

If you use [sdkman]() on Mac, it's pretty easy to get the right version installed:
If you have `sdkman_auto_env=true` in your `~/.sdkman/etc/config`, then when you switch to the project folder, the correct
JVM will be selected automatically.

```
sdk install java $(cat .java-version) && sdk use java $(cat .java-version)
gu install native-image
```

If you want to test against a locally running service, you'll need to run the cli with the following environment
variable:
You can also type: `sdk env` and the correct JVM will be used while in the project folder.

```
OKTA_CLI_BASE_URL=http://localhost:8080/
```
Build with: `mvn clean install`

**NOTE**: The backend service code is currently in a private repo.
**NOTE:** On IntelliJ (at least), you'll also need to add in the Lombok plugin to avoid compiler errors on getters and setters for data classes.

You can then run the Okta cli with: `./cli/target/okta`
28 changes: 27 additions & 1 deletion cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>com.okta.cli</groupId>
<artifactId>okta-cli-tools</artifactId>
<version>0.3.2-SNAPSHOT</version>
<version>0.4.0-SNAPSHOT</version>
</parent>

<artifactId>okta-cli</artifactId>
Expand Down Expand Up @@ -89,6 +89,18 @@
<version>1.0-rc6</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.4.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -185,6 +197,7 @@
<executable>native-image</executable>
<arguments>
<argument>--no-fallback</argument>
<argument>--no-server</argument>
<argument>--enable-url-protocols=http,https</argument>
<argument>-H:ResourceConfigurationFiles=src/main/graalvm/resource-config.json</argument>
<argument>-H:ReflectionConfigurationFiles=src/main/graalvm/reflect-config.json,src/main/graalvm/okta-sdk-reflect-config.json</argument>
Expand All @@ -198,6 +211,19 @@
</configuration>
</plugin>

<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<!-- Setting thsi fixes an issue when running javadoc -->
<!-- https://bugs.openjdk.java.net/browse/JDK-8212233 -->
<Automatic-Module-Name>com.okta.cli</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions cli/src/main/graalvm/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@
}
]
},
{
"name": "com.okta.cli.common.model.ErrorResponse",
"allDeclaredFields": true,
"allDeclaredMethods": true,
"allPublicMethods": true,
"allPublicFields": true,
"methods": [
{
"name": "<init>",
"parameterTypes": []
}
]
},
{
"name": "org.yaml.snakeyaml.Yaml",
"allDeclaredFields": true,
Expand Down
56 changes: 48 additions & 8 deletions cli/src/main/java/com/okta/cli/commands/Register.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@

import com.okta.cli.OktaCli;
import com.okta.cli.common.model.OrganizationRequest;
import com.okta.cli.common.model.OrganizationResponse;
import com.okta.cli.common.model.RegistrationQuestions;
import com.okta.cli.common.service.DefaultSetupService;
import com.okta.cli.common.service.SetupService;
import com.okta.cli.console.PromptOption;
import com.okta.cli.console.Prompter;
import picocli.CommandLine;
import picocli.CommandLine.Command;

import java.util.List;
import java.util.concurrent.Callable;

@Command(name = "register",
Expand All @@ -44,22 +48,58 @@ public class Register implements Callable<Integer> {
@CommandLine.Option(names = "--company", description = "Company / organization used when registering a new Okta account")
protected String company;

protected OrganizationRequest organizationRequest() {
Prompter prompter = standardOptions.getEnvironment().prompter();
return new OrganizationRequest()
.setFirstName(prompter.promptUntilValue(firstName, "First name"))
.setLastName(prompter.promptUntilValue(lastName, "Last name"))
.setEmail(prompter.promptUntilValue(email, "Email address"))
.setOrganization(prompter.promptUntilValue(company, "Company"));
protected CliRegistrationQuestions registrationQuestions() {
return new CliRegistrationQuestions();
}

@Override
public Integer call() throws Exception {

CliRegistrationQuestions registrationQuestions = registrationQuestions();

SetupService setupService = new DefaultSetupService(null);
setupService.createOktaOrg(this::organizationRequest,
OrganizationResponse orgResponse = setupService.createOktaOrg(registrationQuestions,
standardOptions.getEnvironment().getOktaPropsFile(),
standardOptions.getEnvironment().isDemo(),
standardOptions.getEnvironment().isInteractive());

String identifier = orgResponse.getId();
setupService.verifyOktaOrg(identifier,
registrationQuestions,
standardOptions.getEnvironment().getOktaPropsFile());

return 0;


// TODO include demo logic?
// if (demo) { // always prompt for user info in "demo mode", this info will not be used but it makes for a more realistic demo
// organizationRequestSupplier.get();
// }
}

private class CliRegistrationQuestions implements RegistrationQuestions {

private final Prompter prompter = standardOptions.getEnvironment().prompter();

@Override
public boolean isOverwriteConfig() {
PromptOption<Boolean> yes = PromptOption.of("Yes", Boolean.TRUE);
PromptOption<Boolean> no = PromptOption.of("No", Boolean.FALSE);
return prompter.promptIfEmpty(null, "Overwrite configuration file?", List.of(yes, no), yes);
}

@Override
public OrganizationRequest getOrganizationRequest() {
return new OrganizationRequest()
.setFirstName(prompter.promptUntilValue(firstName, "First name"))
.setLastName(prompter.promptUntilValue(lastName, "Last name"))
.setEmail(prompter.promptUntilValue(email, "Email address"))
.setOrganization(prompter.promptUntilValue(company, "Company"));
}

@Override
public String getVerificationCode() {
return prompter.promptUntilValue("Verification code");
}
}
}
7 changes: 5 additions & 2 deletions cli/src/main/java/com/okta/cli/commands/apps/AppsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import com.okta.cli.common.model.AuthorizationServer;
import com.okta.cli.common.model.ClientCredentials;
import com.okta.cli.console.ConsoleOutput;
import com.okta.commons.lang.Assert;
import com.okta.sdk.client.Client;
import com.okta.sdk.client.Clients;
import com.okta.sdk.resource.ExtensibleResource;
import com.okta.sdk.resource.application.Application;
import com.okta.sdk.resource.application.OpenIdConnectApplication;
import picocli.CommandLine;

import java.util.concurrent.Callable;
Expand All @@ -43,8 +45,9 @@ public Integer call() {
Application app = client.getApplication(appName);

ConsoleOutput out = standardOptions.getEnvironment().getConsoleOutput();

// TODO verify this is an OIDC app

Assert.isInstanceOf(OpenIdConnectApplication.class, app, "Existing application found with name '" +
appName +"' but it is NOT an OIDC application. Only OIDC applications work with the Okta CLI.");

ClientCredentials clientCreds = new ClientCredentials(client.http()
.get("/api/v1/internal/apps/" + app.getId() + "/settings/clientcreds", ExtensibleResource.class));
Expand Down
7 changes: 2 additions & 5 deletions cli/src/main/java/com/okta/cli/console/DefaultPrompter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,13 @@

public class DefaultPrompter implements Prompter, Closeable {

private final BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
private final BufferedReader consoleReader;

private final ConsoleOutput out;

public DefaultPrompter() {
this(ConsoleOutput.create(false));
}

public DefaultPrompter(ConsoleOutput consoleOutput) {
this.out = consoleOutput;
this.consoleReader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
}

@Override
Expand Down
Loading

0 comments on commit e44a470

Please sign in to comment.