Install & authenticate

Install, authenticate, and initialize Moov.js in your application.

After installation, you’ll generate a token server-side to communicate between Moov and your account. You’ll also set scopes to make API calls from Moov.js.

Install

Include Moov.js in your application by loading the Moov.js script, or downloading the Moov.js package via npm.

1
<script type="text/javascript" src="https://js.moov.io/v1"></script>
1
npm i @moovio/moov-js

Authenticate

For each action you take with Moov.js, you’ll need a unique short lived access token that contains information needed to securely communicate with your Moov account.

You must generate tokens from your server-side application. Once you’ve generated a token, send it back to your client to use with Moov.js.

Token generation process diagram

Create an access token

The examples below create an access token with a scope set to create an account. See the scopes and the Node scopes documentation for more information.

1
2
3
4
curl -X POST "https://api.moov.io/oauth2/token" \
  -u "PUBLIC_KEY:PRIVATE_KEY" \
  --data-urlencode "grant_type=client_credentials" \
  --data-urlencode  "scope=/accounts.write" \
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import { Moov, SCOPES } from '@moovio/node';

const moov = new Moov({
  accountID: "YOUR_MOOV_ACCOUNT_ID",
  publicKey: "PUBLIC_KEY",
  secretKey: "PRIVATE_KEY",
  domain: "YOUR_DOMAIN"
});

const scopes = [SCOPES.ACCOUNTS_CREATE];
try {
  const {token} = await moov.generateToken(scopes);
  // Do something with token
} catch(err) {
  // Handle any errors
}

Initialize

Once you’ve generated a token from your server, initialize Moov.js in the browser by passing the token to Moov.

1
2
3
<script>
  const moov = Moov(token)
</script>
1
2
3
4
import { loadMoov } from '@moovio/moov-js';

const moovAccessToken = await fetch(...);
const moov = await loadMoov(moovAccessToken);

Next steps

  • Learn what scopes are available for Moov.js actions
  • Check out Moov.js Drops, a collection of UI components
Summary Beta