io.sphere.sdk.client.TokensFacade Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commercetools-java-client-core Show documentation
Show all versions of commercetools-java-client-core Show documentation
This SDK is announced to be deprecated latest by 31 December 2022, please follow more details on SDK deprecation plan https://docs.commercetools.com/api/releases/2021-08-31-announced-long-term-support-plan-for-commercetools-sdks. We recommend you to use our new SDK here https://docs.commercetools.com/sdk/jvm-sdk#java-sdk-v2.
package io.sphere.sdk.client;
import io.sphere.sdk.models.Base;
import java.util.concurrent.CompletionStage;
/**
* Provides facilities to fetch commercetools access and refresh tokens.
*/
public final class TokensFacade extends Base {
private TokensFacade() {
}
public static CompletionStage fetchAccessToken(final SphereAuthConfig authConfig) {
return fetchTokens(authConfig).thenApply(Tokens::getAccessToken);
}
/**
* Fetches a new access token using the client credentials flow.
*
* {@include.example io.sphere.sdk.client.TokensFacadeIntegrationTest#fetchAccessToken()}
*
* @param authConfig the commercetools project which the token should belong to
* @return token
*/
public static CompletionStage fetchTokens(final SphereAuthConfig authConfig) {
return TokensSupplier.of(authConfig, SphereClientFactory.of().createHttpClient(), true).get();
}
/**
* Fetches a new access token using the customer password flow.
*
* {@include.example io.sphere.sdk.client.TokensFacadeIntegrationTest#passwordFlowDemo()}
*
* @param authConfig authConfig
* @param email email
* @param password password
* @return token
*/
public static CompletionStage fetchCustomerPasswordFlowTokens(final SphereAuthConfig authConfig, final String email, final String password) {
return TokensSupplier.ofCustomerPasswordFlowTokens(authConfig, email, password, SphereClientFactory.of().createHttpClient(), true).get();
}
}