Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client-samples/java/rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Now that we have the file private key in a usable format we can use the Java Cli
## Configuring the Java Client

### Properties
Make these changes to the `META-INF/microprofile-config.properties` resource file
Make these changes to the `META-INF/microprofile-config.properties` resource file. Alternatively, you can use the [`CreateConfig`](./src/main/java/com/ms/infra/example/application/CreateConfig.java) script to help generate it for you.

| Property Name | Description | Required |
|-----------------------------------|-----------------------------------------------------------------------------------------|----------|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package com.ms.infra.example.application;

import java.util.HashMap;

import java.util.Map;
import java.util.Scanner;
import java.util.Properties;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class CreateConfig {
private static Scanner scanner;

public static void main(String... args) throws Exception {
scanner = new Scanner(System.in);
createPropertiesFile(
getEnv(),
getClientID(),
getAppScope(),
getPrivateKeyFile(),
getPublicKeyFile(),
getProxyConfig()
);
scanner.close();
}

public static void createPropertiesFile(String env, String clientId, String clientAppScope, String privateKeyFile, String publicKeyFile, Map<String, String> proxyConfig) {
String uatOption = env.equals("UAT") ? "-uat" : "";

Properties properties = new Properties();
properties.setProperty(
"morgan-stanley-oauth2-token-uri",
String.format("https://login.microsoftonline.com/api%s.morganstanley.com/oauth2/v2.0/token", uatOption)
);
properties.setProperty("client-app-id", clientId);
properties.setProperty("client-app-scope", clientAppScope);
properties.setProperty("private-key-file", privateKeyFile);
properties.setProperty("public-certificate-file", publicKeyFile);
properties.setProperty(
"ms-url-api-domain",
String.format("https://api%s.morganstanley.com/", uatOption)
);

if (!proxyConfig.isEmpty()) {
properties.setProperty("proxy-host", proxyConfig.get("proxy_host"));
properties.setProperty("proxy-port", proxyConfig.get("proxy_port"));
}

Path configPath = Path.of(String.format("src/main/resources/META-INF/microprofile-config%s.properties", uatOption));

try {
Files.createDirectories(configPath.getParent()); // Ensure directory exists
try (FileOutputStream out = new FileOutputStream(configPath.toFile())) {
properties.store(out, "MicroProfile Configuration File");
}
System.out.println("Config file created: " + configPath.toAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
}

public static String getClientID() {
System.out.println("Please enter your client ID");
System.out.println("e.g. 12345678-abcd-1234-efgh-1234567890ab");

System.out.print("Client ID: ");
return scanner.nextLine().trim();
}

public static String getAppScope() {
System.out.println("\nPlease enter your app scope");
System.out.println("e.g. https://api-uat.morganstanley.com/hello-world/.default");

System.out.print("App Scope: ");
return scanner.nextLine().trim();
}

public static String getPrivateKeyFile() {
System.out.println("\nPlease enter your private key file (should end in .der)");
String privateKeyFile = "";
while (!privateKeyFile.endsWith(".der")) {
System.out.print("Private Key File: ");
privateKeyFile = scanner.nextLine().trim();

if (privateKeyFile.endsWith(".pem")) {
System.out.println("You need to have a der encoded file, you can create one by using:");
System.out.println("openssl pkcs8 -topk8 -inform PEM -outform DER -in private_key.pem -out private_key.der -nocrypt\n");
}
else if (!privateKeyFile.endsWith(".der")) {
System.out.println("Your file should end in .der\n");
}
}
return privateKeyFile;
}

public static String getPublicKeyFile() {
System.out.println("\nPlease enter your public key file (should end in .cer)");
String publicKeyFile = "";
while (!publicKeyFile.endsWith(".cer")) {
System.out.print("Public Key File: ");
publicKeyFile = scanner.nextLine().trim();

if (!publicKeyFile.endsWith(".cer")) {
System.out.println("Your file should end in .cer\n");
}
}
return publicKeyFile;
}

public static Map<String, String> getProxyConfig() {
Map<String, String> proxyConfig = new HashMap<>();

String option = "";

while (!option.equals("y") && !option.equals("n")) {
System.out.println("\nWould you like to add a proxy config?");
System.out.print("\n y -> Yes\n n -> No\n Choice: ");
option = scanner.nextLine().trim().toLowerCase();
}

if (option.equals("n")) {
return proxyConfig;
};

System.out.print("Please enter the proxy host: ");
String proxyHost = scanner.nextLine().trim();
proxyConfig.put("proxy_host", proxyHost);

String proxyPort;
while (true) {
try {
System.out.print("Please enter the proxy port: ");
proxyPort = scanner.nextLine().trim();
Integer.parseInt(proxyPort);
break;
} catch (NumberFormatException e) {
System.out.println("Error: The proxy port must be an integer.\n");
}
}
proxyConfig.put("proxy_port", proxyPort);

return proxyConfig;
}

public static String getEnv() {
String option = "";

while (!option.equals("u") && !option.equals("p")) {
System.out.println("\nWhich environment is this for?");
System.out.print("\n u -> UAT\n p -> Production\n Choice: ");
option = scanner.nextLine().trim().toLowerCase();
}

if (option.equals("u")) {
return "UAT";
}
return "prod";
}
}
2 changes: 1 addition & 1 deletion client-samples/java/websockets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The `der` output format is a just an encoding format, to find out more check <ht
Now that we have the file private key in a usable format we can use the Java Client to test the connection to Morgan Stanley's API offering.

### Properties
Make these changes to the `META-INF/microprofile-config.properties` resource file
Make these changes to the `META-INF/microprofile-config.properties` resource file. Alternatively, you can use the [`CreateConfig`](./src/main/java/com/ms/infra/example/application/CreateConfig.java) script to help generate it for you.

| Property Name | Description | Required |
|-----------------------------------|-----------------------------------------------------------------------------------------|----------|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package com.ms.infra.example.application;

import java.util.HashMap;

import java.util.Map;
import java.util.Scanner;
import java.util.Properties;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class CreateConfig {
private static Scanner scanner;

public static void main(String... args) throws Exception {
scanner = new Scanner(System.in);
createPropertiesFile(
getEnv(),
getClientID(),
getAppScope(),
getPrivateKeyFile(),
getPublicKeyFile(),
getProxyConfig()
);
scanner.close();
}

public static void createPropertiesFile(String env, String clientId, String clientAppScope, String privateKeyFile, String publicKeyFile, Map<String, String> proxyConfig) {
String uatOption = env.equals("UAT") ? "-uat" : "";

Properties properties = new Properties();
properties.setProperty(
"morgan-stanley-oauth2-token-uri",
String.format("https://login.microsoftonline.com/api%s.morganstanley.com/oauth2/v2.0/token", uatOption)
);
properties.setProperty("client-app-id", clientId);
properties.setProperty("client-app-scope", clientAppScope);
properties.setProperty("private-key-file", privateKeyFile);
properties.setProperty("public-certificate-file", publicKeyFile);
properties.setProperty(
"ms-url-api-domain",
String.format("https://api%s.morganstanley.com/", uatOption)
);

if (!proxyConfig.isEmpty()) {
properties.setProperty("proxy-host", proxyConfig.get("proxy_host"));
properties.setProperty("proxy-port", proxyConfig.get("proxy_port"));
}

Path configPath = Path.of(String.format("src/main/resources/META-INF/microprofile-config%s.properties", uatOption));

try {
Files.createDirectories(configPath.getParent()); // Ensure directory exists
try (FileOutputStream out = new FileOutputStream(configPath.toFile())) {
properties.store(out, "MicroProfile Configuration File");
}
System.out.println("Config file created: " + configPath.toAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
}

public static String getClientID() {
System.out.println("Please enter your client ID");
System.out.println("e.g. 12345678-abcd-1234-efgh-1234567890ab");

System.out.print("Client ID: ");
return scanner.nextLine().trim();
}

public static String getAppScope() {
System.out.println("\nPlease enter your app scope");
System.out.println("e.g. https://api-uat.morganstanley.com/hello-world/.default");

System.out.print("App Scope: ");
return scanner.nextLine().trim();
}

public static String getPrivateKeyFile() {
System.out.println("\nPlease enter your private key file (should end in .der)");
String privateKeyFile = "";
while (!privateKeyFile.endsWith(".der")) {
System.out.print("Private Key File: ");
privateKeyFile = scanner.nextLine().trim();

if (privateKeyFile.endsWith(".pem")) {
System.out.println("You need to have a der encoded file, you can create one by using:");
System.out.println("openssl pkcs8 -topk8 -inform PEM -outform DER -in private_key.pem -out private_key.der -nocrypt\n");
}
else if (!privateKeyFile.endsWith(".der")) {
System.out.println("Your file should end in .der\n");
}
}
return privateKeyFile;
}

public static String getPublicKeyFile() {
System.out.println("\nPlease enter your public key file (should end in .cer)");
String publicKeyFile = "";
while (!publicKeyFile.endsWith(".cer")) {
System.out.print("Public Key File: ");
publicKeyFile = scanner.nextLine().trim();

if (!publicKeyFile.endsWith(".cer")) {
System.out.println("Your file should end in .cer\n");
}
}
return publicKeyFile;
}

public static Map<String, String> getProxyConfig() {
Map<String, String> proxyConfig = new HashMap<>();

String option = "";

while (!option.equals("y") && !option.equals("n")) {
System.out.println("\nWould you like to add a proxy config?");
System.out.print("\n y -> Yes\n n -> No\n Choice: ");
option = scanner.nextLine().trim().toLowerCase();
}

if (option.equals("n")) {
return proxyConfig;
};

System.out.print("Please enter the proxy host: ");
String proxyHost = scanner.nextLine().trim();
proxyConfig.put("proxy_host", proxyHost);

String proxyPort;
while (true) {
try {
System.out.print("Please enter the proxy port: ");
proxyPort = scanner.nextLine().trim();
Integer.parseInt(proxyPort);
break;
} catch (NumberFormatException e) {
System.out.println("Error: The proxy port must be an integer.\n");
}
}
proxyConfig.put("proxy_port", proxyPort);

return proxyConfig;
}

public static String getEnv() {
String option = "";

while (!option.equals("u") && !option.equals("p")) {
System.out.println("\nWhich environment is this for?");
System.out.print("\n u -> UAT\n p -> Production\n Choice: ");
option = scanner.nextLine().trim().toLowerCase();
}

if (option.equals("u")) {
return "UAT";
}
return "prod";
}
}
3 changes: 2 additions & 1 deletion client-samples/python/rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Create a file, config.json, with the following properties:
- `client_id`: Your Client Id for the Morgan Stanley API Platform. This is a GUID.
- `scopes`: A list of scopes to request a token against, corresponding to the API you are calling. For help with finding the correct scope, please talk to your Morgan Stanley contact.
- `thumbprint`: The thumbprint (also known as fingerprint) of your certificate, without colon separators. For example `AB48C0D31F95EBF8425AECF3E7E6FA92B34C8D47`
- You can get this by looking at the file via windows file explorer or running the following command `openssl x509 -in public_key.cer -noout -fingerprint -sha1 | sed 's/://g' | awk '{print tolower($0)}' | cut -d= -f2`
- `private_key_file`: The path to your private key. This can be either an absolute or relative path. For example: `certs/private_key.pem`
- `tenant`: The tenant you are requesting an access token against.
- UAT: `api-uat.morganstanley.com`
Expand All @@ -28,7 +29,7 @@ Create a file, config.json, with the following properties:
- `requests_ca_bundle`: The file to use as the CA bundle when verifying HTTPS certificates. If omitted, use the default bundle shipped with the `requests` library. Please see the [SSL validation section](#ssl-validation-issues-and-the-requests-ca-bundle) for more details.
- `disable_ssl_verification`: Explicitly disable SSL verification. **Not recommended for security reasons.**

You can use `config-example.json` as a starting point.
You can use `config-example.json` as a starting point, or run `python setup-config.py` to generate it with a cli.

> NOTE: You may recieve a Thumbprint in the format 12:AB:FC:12. Please remove the ":" characters, the thumbrpint should look like 12ABFC12

Expand Down
Loading