Skip to content

Commit

Permalink
Improve README, fix links, misc. cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Lowry authored and EthanML committed Nov 20, 2023
1 parent 1a263e9 commit 2c57e1e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
43 changes: 26 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,49 @@ JavaScript SDK for connecting to a financial institution via MoneyKit Connect in
npm install @moneykit/connect
```

- To use MoneyKit Connect you must first [create a Link Session](https://docs.moneykit.com/openapi/core/#operation/create_link_session) via the MoneyKit API to acquire a Link Session Token
- Once you have a Link Session Token, create your MoneyKit Connect instance
To use MoneyKit Connect you must first [create a Link Session](https://docs.moneykit.com/link-session/create-link-session) via the MoneyKit API to acquire a Link Session Token.

Once you have a Link Session Token, create your MoneyKit Connect instance:

```js
import MoneyKit from "@moneykit/connect";
const linkSessionToken = "get-from-moneykit-api"; // https://docs.moneykit.com/openapi/core/#operation/create_link_session
const linkSessionToken = "get-from-moneykit-api"; // https://docs.moneykit.com/link-session/create-link-session

const moneykit = new MoneyKit();
moneykit.link(linkSessionToken);
```

You may now launch the MoneyKit Connect flow by calling `link()` with your link session token. This will open a popup window to MoneyKit Connect in which the user may select and log into their financial institution, select their accounts and grant permissions.

The `link` method also accepts three optional callback parameters:
You may then launch the MoneyKit Connect flow by calling `link()` with your link session token. This will open a popup window to MoneyKit Connect in which the user may select and log into their financial institution, select their accounts and grant permissions.

- `onLinkSuccess` - called when the linking process completes successfully. This callback will be passed two arguments: an exchangeable MoneyKit API token (see below) and the Institution which was linked. The linked institution also includes a subset of data from financial accounts linked by the user including account type, name and mask.
- `onLinkExit` - called whenever the link process is exited manually by the user. Receives no arguments at this time.
- `onLinkEvent` - called whenever various events occur at different stages of the linking process, as indicated by the Event object argument. Can be used to tailor or notify your application as a user progresses through a link.
To support institutions that use OAuth login it is required that you also provide a `redirect_uri` when creating your Link Session. This URI should point to a page within your app which re-initializes MoneyKit Connect via its `continue()` method. This method requires the URL that was redirected to as its first parameter (the URL should include any query parameters appended by MoneyKit during the redirect).

### OAuth Flows
Both the `link` and `continue` methods accept the same three optional callback parameters which you should use to handle the results of the link process:

Many Financial Institutions require users to authorize the connection via OAuth on the institution's own website.
- `onLinkSuccess`: called when the linking process completes successfully. This callback will be passed two parameters: an exchangeable MoneyKit API token (see [Link Token Exchange](#link-token-exchange) below) and the Institution which was linked. The linked institution also includes a subset of data from financial accounts linked by the user including account type, name and mask.
- `onLinkExit`: called whenever the link process is exited manually by the user. Receives no parameters at this time.
- `onLinkEvent`: called whenever various events occur at different stages of the linking process, as indicated by the Event object parameter. Can be used to tailor or notify your application as a user progresses through a link.

To support this workflow you must provide a `redirect_uri` when creating a Link Session via the MoneyKit API. This URI should go to a page of yours which can re-initialize MoneyKit Connect via its `continue()` method. This method requires the URL that was redirected to as its first argument (the URL should include all query parameters appended by MoneyKit during the redirect) followed by all of the same optional callbacks detailed for the `link()` method above.
### Example

```js
// my-redirect-page.js
import MoneyKit from "@moneykit/connect";
const moneykit = new MoneyKit();
// Present Connect to the user
moneykit.link(linkSessionToken, (exchangeableToken, institution) => {
console.log(exchangeableToken, institution);
});

/**
* Required for OAuth institutions.
* This will present Connect again and allow the user to continue their link
* in progress after completing OAuth with their financial institution.
*
* This `continue()` call should be performed on the page you indicated
* as your `redirect_uri` when creating a Link Session.
* The complete URL that was redirected to should be passed as the first argument.
*/
moneykit.continue(window.location.href, (exchangeableToken, institution) => {
console.log(exchangeableToken, institution);
});
```

## Link Token Exchange

To finalize the connection and acquire a link ID with which to make subsequent requests, you must pass your exchangeable token received upon completion of a user's connection to your secure backend service. It should then [exchange](https://docs.moneykit.com/openapi/core/#operation/exchange_token) the token for a link ID via the MoneyKit API.
To finalize the connection and acquire a link ID with which to make subsequent API requests, you must pass your exchangeable token received upon completion of a user's connection to your secure backend service. It should then [exchange](https://docs.moneykit.com/link-session/exchange-token) the token for a link ID via the MoneyKit API.
2 changes: 1 addition & 1 deletion index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "@moneykit/connect",
"description": "MoneyKit Connect launcher for web.",
"version": "0.2.2",
"version": "0.2.3",
"author": "MoneyKit",
"repository": {
"type": "git",
"url": "https://github.com/moneykit/connect-js.git"
},
"types": "./types/index.d.ts",
"license": "MIT",
"dependencies": {
"query-string": "^8.1.0"
},
Expand Down
Loading

0 comments on commit 2c57e1e

Please sign in to comment.