Dropbox
A set of Dropbox API utilities
Installation
yarn add @node-api-toolkit/dropbox
Utilities
@node-api-toolkit/dropbox/auth
- Authenticates the user using oauth.
Usage
To Prototype
Run
yarn run create-dropbox-token-file --tokenIdentifier YOUR-TOKEN-IDENTIFIER
Then you can manually use the token by using save-token/getToken
. Read those
docs for more info
@node-api-toolkit/dropbox/auth
import express = require("express");
import auth from "@node-api-toolkit/dropbox/auth";
const app = express();
const server = app.listen(8888);
app.get("/success", (req, res) => {
res.json({
success: true
});
});
app.get("/failure", (req, res) => {
res.json({
success: false
});
});
const onOauthSuccess = ({ accessToken, refreshToken, profile }) => {
return new Promise(resolve => {
const modifiedUser = {
...profile,
metadata: {
jwtToken: "123"
}
};
User.findOrCreate({ providerId: profile.userId }, (err, user) => {
if (err) {
throw new Error(err);
}
return resolve(user);
});
});
};
auth({
appKey: "KEY",
appSecret: "SECRET",
onOauthSuccess,
expressApp: app,
callbackURL: "http://localhost:8888/auth/dropbox/callback",
successRedirect: "/success",
failureRedirect: "/failure"
});
Tests
This package is thoroughly tested. All tests located in __tests__
You should run tests from the monorepo root. But you can also run them individually.
Both accept the following yarn run
commands:
yarn run test
: Runs tests with mocks (mocks API)test:watch
: Watches tests (use for development)test:debug
: Prints debug informationyarn run test:watch:debug
: Prints debug info in watch modeyarn run test:integration
: Uses the real APIs to test. Note you need to set up the token using yarn run create-jest-dropbox-token-file
yarn run test:integration:watch
: Uses the real APIs to test in watch mode. Note you need to set up the token using yarn run create-jest-dropbox-token-file
To run tests with the real API, you must first generate a JEST token.
yarn run create-jest-dropbox-token-file