Mediator Credentials

To authenticate as a Mediator 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 Mediator 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: 'https://instance-url.btcore.app',
  // 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({
    // We strongly recommend injecting this insted of letting it hardcoded
    email: process.env.BITCAPITAL_EMAIL,
    password: process.env.BITCAPITAL_PASSWORD,
  });

  // The session returns the mediator user info and its credentials
  console.log(user.credentials.accessToken);

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

} catch(exception) {
  // Something went wrong, probably credentials are invalid
  console.error(exception);
}
curl \
  -H "Authorization: Basic $(echo \"$CLIENT_ID:$CLIENT_SECRET\" | base64)" \
  --data "grant_type=password&username=$BITCAPITAL_EMAIL&password=$BITCAPITAL_PASSWORD" \
  https://instance-url.btcore.app/oauth/token
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 {
    @FormUrlEncoded
    @POST("oauth/token")
    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
      .baseUrl("https://testnet.btcore.app")
      // Uses GSON for serialization
      .addConverterFactory(GsonConverterFactory.create())
      .build();
    
    // 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()
  }
}

Managing your consumer sub-accounts

Mediator is a special kind of user account that enables it to hold any number of additional consumer sub-accounts. As a mediator, you can operate over its wallets and its sub accounts wallets.


What’s Next