GuidesAPI ReferenceCommunity
GuidesCommunityLog In

Consumer Credentials

To authenticate as a Consumer in the API, you'll need some credentials associated with the Domain you intend to operate within.

  • The base URL for the instance your Domain was assigned to
  • A set of valid Client Credentials as a Base64 Authorization Header.
  • A set of valid Consumer credentials (email and password)
import Bitcapital from 'bitcapital-core-sdk';

// Initialize the session instance to authenticate
// using the Bitcapital Core OAuth 2.0 provider.
const bitcapital = Bitcapital.initialize({
  // Instance URL for REST API calls
  baseURL: '',
  // Credentials for OAuth 2.0 requests
  clientId: '< YOUR CLIENT_ID HERE >',
  clientSecret: '< YOUR CLIENT_SECRET HERE >',

try {
  // Authenticate a user with email and password from Bitcapital Core
  // If succeeds and available, the credentials will be stored in the 
  // session instance and in the local storage (for browser environments).
  const user = await bitcapital.session().password({
    email: "[email protected]",
    password: "sample_password_123",

  // The session returns the consumer user info and its credentials

  // To logout and clear the current credentials, use the "destroy" action
  await bitcapital.session().destroy();

} catch(exception) {
  // Something went wrong, probably credentials are invalid
curl \
  -H "Authorization: Basic $(echo \"CLIENT_ID:CLIENT_SECRET\" | base64)" \
  --data "grant_type=password&[email protected]&password=sample_password123" \
public class BitcapitalClient {
  public static class OAuthTokenResponse {
    public String access_token;
    public String refreshToken;
    public String expiresIn;
    public String userId;
   * Uses Retrofit2 annotations for HTTP request mapping.
  public static interface OAuthWebService {
    Call<OAuthTokenResponse> token(
      @Header("Authorization") String basic, 
      @Field("username") String email, 
      @Field("password") String password, 
      @Field("scopes") String [] scopes, 
      @Field("grant_type") String grantType

   * Executes an OAuth 2.0 authentication using OkHttp3 and Retrofit2.
  public static Call<> execute() {
    Retrofit retrofit = new Retrofit.Builder()
      // Add your instance URL
      // Uses GSON for serialization
    // Initialize the oauth web service interface
    OAuthWebService oauthWebService = retrofit.create(OAuthWebService.class);  
    // TODO: Put your params in the request call
    return oauthWebService.token(...params).execute().body()

For more information, checkout de OAuth 2.0 API Reference.

Did this page help you?