passport-ground-truth
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

passport-ground-truth

Passport strategy for authenticating with HexLab's Ground Truth using the OAuth 2.0 API.

This module lets you authenticate using Ground Truth in your Node.js applications. You can easily use Passport to integrate into different frameworks like express.

Install

$ npm install passport-ground-truth --save

Usage

Configure Strategy

The Ground Truth authentication strategy authenticates users using a Ground Truth account and Oauth 2.0 tokens. The strategy requires a verify callback, which accepts these credentials and calls done providing a user, as well as options, specifying a client ID, client secret, base URL, and callback URL.

import { Strategy as GroundTruthStrategy } from "passport-ground-truth";

passport.use(
  new GroundTruthStrategy(
    {
      clientID: process.env.GROUND_TRUTH_CLIENT_ID,
      clientSecret: process.env.GROUND_TRUTH_CLIENT_SECRET,
      baseURL: process.env.GROUND_TRUTH_URL,
      callbackURL: "/auth/login/callback",
    },
    async (req, accessToken, refreshToken, profile, done) {
      User.findOrCreate({ id: profile.id }, function (err, user) {
        return done(err, user);
      });
    }
  )
);

Authenticate Requests

Use passport.authenticate(), specifying the "groundtruth" strategy, to authenticate requests.

For example, as route middleware in an Express application:

import express from "express";

export let authRoutes = express.Router();

authRoutes.get("/login", passport.authenticate("groundtruth"));

authRoutes.get(
  "/login/callback",
  passport.authenticate("groundtruth", {
    failureRedirect: "/",
    successReturnToOrRedirect: "/",
  }),
  (req, res) => {
    // Successful authentication, redirect home.
    res.redirect("/");
  }
);

Attribution

License

The MIT License

/passport-ground-truth/

    Package Sidebar

    Install

    npm i passport-ground-truth

    Weekly Downloads

    10

    Version

    1.0.3

    License

    MIT

    Unpacked Size

    8.25 kB

    Total Files

    7

    Last publish

    Collaborators

    • agoyal1