public final class SphereClientConfig extends Base implements SphereAuthConfig, SphereApiConfig, SphereCorrelationIdConfig
SphereClientConfigBuilder| Modifier and Type | Field and Description |
|---|---|
static String |
ENVIRONMENT_VARIABLE_API_URL_SUFFIX |
static String |
ENVIRONMENT_VARIABLE_AUTH_URL_SUFFIX |
static String |
ENVIRONMENT_VARIABLE_CLIENT_ID_SUFFIX |
static String |
ENVIRONMENT_VARIABLE_CLIENT_SECRET_SUFFIX |
static String |
ENVIRONMENT_VARIABLE_PROJECT_KEY_SUFFIX |
static String |
ENVIRONMENT_VARIABLE_SCOPES_SUFFIX |
static String |
PROPERTIES_KEY_API_URL_SUFFIX |
static String |
PROPERTIES_KEY_AUTH_URL_SUFFIX |
static String |
PROPERTIES_KEY_CLIENT_ID_SUFFIX |
static String |
PROPERTIES_KEY_CLIENT_SECRET_SUFFIX |
static String |
PROPERTIES_KEY_PROJECT_KEY_SUFFIX |
static String |
PROPERTIES_KEY_SCOPES_SUFFIX |
| Modifier and Type | Method and Description |
|---|---|
String |
getApiUrl() |
String |
getAuthUrl()
The url of the OAuth server including http protocol and ports.
|
String |
getClientId() |
String |
getClientSecret() |
CorrelationIdGenerator |
getCorrelationIdGenerator() |
String |
getProjectKey() |
List<String> |
getRawScopes()
Gets the scopes which have a more complex structure then the scopes returned by
SphereAuthConfig.getScopes(). |
List<String> |
getScopes()
Gets the scopes which are permitted.
|
static SphereClientConfig |
of(String projectKey,
String clientId,
String clientSecret) |
static SphereClientConfig |
of(String projectKey,
String clientId,
String clientSecret,
String authUrl,
String apiUrl) |
static SphereClientConfig |
of(String projectKey,
String clientId,
String clientSecret,
String authUrl,
String apiUrl,
CorrelationIdGenerator correlationIdGenerator) |
static SphereClientConfig |
of(String projectKey,
String clientId,
String clientSecret,
String authUrl,
String apiUrl,
List<String> scopes) |
static SphereClientConfig |
ofEnvironmentVariables(String prefix)
Creates a
SphereClientConfig out of environment variables using prefix as namespace parameter. |
static SphereClientConfig |
ofProperties(Properties properties,
String prefix)
|
SphereClientConfig |
withApiUrl(String apiUrl) |
SphereClientConfig |
withAuthUrl(String authUrl) |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitofof, of, ofpublic static final String ENVIRONMENT_VARIABLE_API_URL_SUFFIX
public static final String ENVIRONMENT_VARIABLE_AUTH_URL_SUFFIX
public static final String ENVIRONMENT_VARIABLE_PROJECT_KEY_SUFFIX
public static final String ENVIRONMENT_VARIABLE_CLIENT_ID_SUFFIX
public static final String ENVIRONMENT_VARIABLE_CLIENT_SECRET_SUFFIX
public static final String ENVIRONMENT_VARIABLE_SCOPES_SUFFIX
public static final String PROPERTIES_KEY_API_URL_SUFFIX
public static final String PROPERTIES_KEY_AUTH_URL_SUFFIX
public static final String PROPERTIES_KEY_PROJECT_KEY_SUFFIX
public static final String PROPERTIES_KEY_CLIENT_ID_SUFFIX
public static final String PROPERTIES_KEY_CLIENT_SECRET_SUFFIX
public static final String PROPERTIES_KEY_SCOPES_SUFFIX
public static SphereClientConfig of(String projectKey, String clientId, String clientSecret)
of in interface SphereAuthConfigpublic static SphereClientConfig of(String projectKey, String clientId, String clientSecret, String authUrl, String apiUrl)
public static SphereClientConfig of(String projectKey, String clientId, String clientSecret, String authUrl, String apiUrl, CorrelationIdGenerator correlationIdGenerator)
public static SphereClientConfig of(String projectKey, String clientId, String clientSecret, String authUrl, String apiUrl, List<String> scopes)
public String getApiUrl()
getApiUrl in interface SphereApiConfigpublic String getAuthUrl()
SphereAuthConfiggetAuthUrl in interface SphereAuthConfigpublic String getClientId()
getClientId in interface SphereAuthConfigpublic String getClientSecret()
getClientSecret in interface SphereAuthConfigpublic String getProjectKey()
getProjectKey in interface SphereApiConfiggetProjectKey in interface SphereAuthConfigpublic CorrelationIdGenerator getCorrelationIdGenerator()
getCorrelationIdGenerator in interface SphereCorrelationIdConfigpublic List<String> getScopes()
final SphereClientConfig config = SphereClientConfigBuilder .ofKeyIdSecret("projectKey", "clientId", "clientSecret") .scopes(asList(SphereProjectScope.MANAGE_CUSTOMERS, SphereProjectScope.VIEW_ORDERS)) .build(); assertThat(config.getScopes()).containsExactly("manage_customers", "view_orders");See the test code.
getScopes in interface SphereAuthConfigpublic List<String> getRawScopes()
SphereAuthConfigSphereAuthConfig.getScopes().
Whereas SphereAuthConfig.getScopes() returns scopes that have a specific simple structure which contains only {projectKey} (e.g manage_project:{projectKey}),
this method can also return scopes with different structure (e.g manage_orders:{projectKey}:{storeKey}).getRawScopes in interface SphereAuthConfigpublic SphereClientConfig withApiUrl(String apiUrl)
public SphereClientConfig withAuthUrl(String authUrl)
public static SphereClientConfig ofEnvironmentVariables(String prefix)
SphereClientConfig out of environment variables using prefix as namespace parameter.
An example environment variable initialization with "EXAMPLE" as prefix:
export EXAMPLE_PROJECT_KEY="YOUR project key"
export EXAMPLE_CLIENT_ID="YOUR client id"
export EXAMPLE_CLIENT_SECRET="YOUR client secret"
export EXAMPLE_AUTH_URL="https://auth.europe-west1.gcp.commercetools.com" #optional parameter
export EXAMPLE_API_URL="https://api.europe-west1.gcp.commercetools.com" #optional parameter
export EXAMPLE_SCOPES="manage_project" #optional parameter
#separate multiple elements with a comma
#export EXAMPLE_SCOPES="manage_customers,view_orders"
The possible suffixes are
"PROJECT_KEY",
"CLIENT_ID",
"CLIENT_SECRET",
"AUTH_URL",
"API_URL" and
"SCOPES".prefix - prefix of the environment variablesSphereClientConfig containing the values of the environment variables.public static SphereClientConfig ofProperties(Properties properties, String prefix)
SphereClientConfig using Properties using prefix as namespace parameter.
An example properties file with "commercetools." (including the dot) as prefix:
commercetools.projectKey=YOUR project key without quotes
commercetools.clientId=YOUR client id without quotes
commercetools.clientSecret=YOUR client secret without quotes
#optional:
commercetools.authUrl=https://auth.europe-west1.gcp.commercetools.com
commercetools.apiUrl=https://api.europe-west1.gcp.commercetools.com
commercetools.scopes=manage_project
#separate multiple scopes with a comma
#commercetools.scopes=manage_customers,view_orders
The possible suffixes are
"projectKey",
"clientId",
"clientSecret",
"authUrl",
"apiUrl" and
"scopes".properties - properties containing the Composable Commerce HTTP API credentialsprefix - prefix of the property keysSphereClientConfig containing the values of the properties.