1.0.3 • Published 3 years ago

passport-ground-truth v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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

1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.3

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago