passport-ground-truth
v1.0.3
Published
Passport authentication strategy for Ground Truth
Downloads
4
Maintainers
Readme
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("/");
}
);