Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@node-api-toolkit/dropbox

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@node-api-toolkit/dropbox

A set of Dropbox API utilities

  • 1.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

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);

// if it succeeds we will be redirected here
// this should be the home page of your app
app.get("/success", (req, res) => {
  res.json({
    success: true
  });
});

// if it fails we will be redirected here
app.get("/failure", (req, res) => {
  res.json({
    success: false
  });
});

// this function gets called when an oauth is successful
// it needs to return back the user that it was given
// with possible metadata attached
// {
//   accessToken: "I_AM_THE_TOKEN",
//   refreshToken: "REFRESH_TOKEN",
//   user: {
//     userId: "123",
//     email: "franz@dropbox.com",
//     name: {
//       givenName: "Franz",
//       familyName: "Ferdinand",
//       displayName: "Franz Ferdinand (Personal)"
//     },
//     profile: expect.anything()
//   }
// }
const onOauthSuccess = ({ accessToken, refreshToken, profile }) => {
  return new Promise(resolve => {
    const modifiedUser = {
      ...profile,
      // attaching metadata
      metadata: {
        jwtToken: "123"
      }
    };

    // we do something to link the access token to the user
    // (User refers to a user model you use to create a user in your database)
    // example:
    User.findOrCreate({ providerId: profile.userId }, (err, user) => {
      if (err) {
        throw new Error(err);
      }
      return resolve(user);
    });
  });
};

// adds auth endpoints to the expressApp
auth({
  appKey: "KEY",
  appSecret: "SECRET",
  onOauthSuccess,

  expressApp: app,
  callbackURL: "http://localhost:8888/auth/dropbox/callback",

  successRedirect: "/success",
  failureRedirect: "/failure"
});

// User now visits the `oauthStartUrl` (default /auth/dropbox)
// http://localhost:8888/auth/dropbox

// The endpoint redirects us to dropbox's oauth server (below).
// usually it would have a login page where the user clicks "Login"
// but here we just mock some text so that we can verify that the
// redirect was successful

// once the user logs in the oauth server will redirect back to
// /auth/dropbox/callback (callbackUrl). We simulate that happening
// http://localhost:8888/auth/dropbox/callback?code=123

// Once the user reaches the callback url, the server will use the
// authorization code (code) to get an oauth token. We mock the
// response from dropbox's api with the access token and refresh
// token

// the callback endpoint then uses the token to reach out and get
// the account details which have the account_id and some other
// metadata

// once the server fetches the user info, it will redirect the user back
// to the /success endpoint we created on top. We are verifying the
// redirect was successful

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 information
  • yarn run test:watch:debug: Prints debug info in watch mode
  • yarn 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

FAQs

Package last updated on 18 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc