public interface SphereAuthConfig
SphereAuthConfigBuilder
Modifier and Type | Method and Description |
---|---|
String |
getAuthUrl()
The url of the OAuth server including http protocol and ports.
|
String |
getClientId() |
String |
getClientSecret() |
String |
getProjectKey() |
default List<String> |
getRawScopes()
Gets the scopes which have a more complex structure then the scopes returned by
getScopes() . |
default List<String> |
getScopes()
Gets the scopes which are permitted.
|
static SphereAuthConfig |
of(String projectKey,
String clientId,
String clientSecret) |
static SphereAuthConfig |
of(String projectKey,
String clientId,
String clientSecret,
String authUrl) |
String getAuthUrl()
String getClientId()
String getClientSecret()
String getProjectKey()
default List<String> getScopes()
final SphereAuthConfig config = SphereAuthConfigBuilder .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.
On insufficient permissions on executing requests ForbiddenException
will be thrown:
final List<SphereScope> scopes = singletonList(SphereProjectScope.VIEW_PRODUCTS); ApiClientFixtures.withApiClient(client(), scopes, apiClient -> { final SphereClientConfig clientConfig = toSphereClientConfig(getSphereClientConfig(), apiClient); try (final SphereClient client = SphereClientFactory.of(IntegrationTest::newHttpClient) .createClient(clientConfig)) { assertThatThrownBy(() -> { final CustomerQuery request = CustomerQuery.of(); SphereClientUtils.blockingWait(client.execute(request), 5, SECONDS); }) .as("since the allowed scope is only to view products, customer data should not be loadable") .isInstanceOf(ForbiddenException.class); } });
See the test code.
default List<String> getRawScopes()
getScopes()
.
Whereas 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}).static SphereAuthConfig of(String projectKey, String clientId, String clientSecret)
static SphereAuthConfig of(String projectKey, String clientId, String clientSecret, String authUrl)