{"id":18530971,"url":"https://github.com/hackgt/passport-ground-truth","last_synced_at":"2025-05-14T22:11:18.745Z","repository":{"id":57320087,"uuid":"390533235","full_name":"HackGT/passport-ground-truth","owner":"HackGT","description":"Ground Truth authentication strategy with Passport and Node.js","archived":false,"fork":false,"pushed_at":"2021-10-06T23:28:05.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-18T21:30:06.076Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HackGT.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-28T23:05:05.000Z","updated_at":"2021-10-06T23:28:08.000Z","dependencies_parsed_at":"2022-08-26T01:10:33.328Z","dependency_job_id":null,"html_url":"https://github.com/HackGT/passport-ground-truth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HackGT%2Fpassport-ground-truth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HackGT%2Fpassport-ground-truth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HackGT%2Fpassport-ground-truth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HackGT%2Fpassport-ground-truth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HackGT","download_url":"https://codeload.github.com/HackGT/passport-ground-truth/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254235701,"owners_count":22036964,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T18:04:40.879Z","updated_at":"2025-05-14T22:11:18.693Z","avatar_url":"https://github.com/HackGT.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# passport-ground-truth\n\n[Passport](https://github.com/jaredhanson/passport) strategy for authenticating with HexLab's [Ground Truth](https://github.com/hackgt/ground-truth) using the OAuth 2.0 API.\n\nThis module lets you authenticate using Ground Truth in your Node.js applications. You can easily use Passport to integrate into different frameworks like express.\n\n## Install\n\n```shell\n$ npm install passport-ground-truth --save\n$ npm install @types/passport-oauth2 --save-dev\n```\n\n## Usage\n\n### Configure Strategy\n\nThe 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.\n\n```js\nimport { Strategy as GroundTruthStrategy } from \"passport-ground-truth\";\n\npassport.use(\n  new GroundTruthStrategy(\n    {\n      clientID: process.env.GROUND_TRUTH_CLIENT_ID,\n      clientSecret: process.env.GROUND_TRUTH_CLIENT_SECRET,\n      baseURL: process.env.GROUND_TRUTH_URL,\n      callbackURL: \"/auth/login/callback\",\n    },\n    async (req, accessToken, refreshToken, profile, done) {\n      User.findOrCreate({ id: profile.id }, function (err, user) {\n        return done(err, user);\n      });\n    }\n  )\n);\n```\n\n### Authenticate Requests\n\nUse `passport.authenticate()`, specifying the `\"groundtruth\"` strategy, to\nauthenticate requests.\n\nFor example, as route middleware in an [Express](http://expressjs.com/)\napplication:\n\n```js\nimport express from \"express\";\n\nexport let authRoutes = express.Router();\n\nauthRoutes.get(\"/login\", passport.authenticate(\"groundtruth\"));\n```\n\n#### Full Code Example (`auth.ts`)\n\n```js\nimport express from \"express\";\nimport fetch from \"node-fetch\";\nimport passport from \"passport\";\n\nexport const authRoutes = express.Router();\n\nauthRoutes.get(\"/login\", passport.authenticate(\"groundtruth\"));\n\nauthRoutes.route(\"/login/callback\").get((req, res, next) =\u003e {\n  if (req.query.error === \"access_denied\") {\n    res.redirect(\"/auth/login\");\n    return;\n  }\n\n  passport.authenticate(\"groundtruth\", {\n    failureRedirect: \"/\",\n    successReturnToOrRedirect: \"/\",\n  })(req, res, next);\n});\n\nauthRoutes.route(\"/check\").get((req, res) =\u003e {\n  if (req.user) {\n    res.status(200).json(req.user);\n  } else {\n    res.status(400).json({ success: false });\n  }\n});\n\nauthRoutes.route(\"/logout\").all(async (req, res) =\u003e {\n  if (req.user) {\n    try {\n      await fetch(new URL(\"/api/user/logout\", process.env.GROUND_TRUTH_URL).toString(), {\n        method: \"POST\",\n        headers: {\n          Authorization: `Bearer ${req.user.token}`,\n        },\n      });\n    } catch (err) {\n      console.error(err);\n    } finally {\n      req.logout();\n    }\n  }\n\n  res.redirect(\"/auth/login\");\n});\n```\n\n## Attribution\n\n- [passport-instagram](https://github.com/jaredhanson/passport-instagram)\n\n## License\n\n[The MIT License](http://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackgt%2Fpassport-ground-truth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhackgt%2Fpassport-ground-truth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackgt%2Fpassport-ground-truth/lists"}