{"id":18470375,"url":"https://github.com/aliencreations/node-authenticator","last_synced_at":"2025-05-12T03:10:00.486Z","repository":{"id":99301703,"uuid":"311122967","full_name":"AlienCreations/node-authenticator","owner":"AlienCreations","description":"Authentication utility for Alien Creations node apps.","archived":false,"fork":false,"pushed_at":"2023-12-11T03:58:40.000Z","size":115,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-09T00:12:48.966Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlienCreations.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-08T18:02:18.000Z","updated_at":"2022-07-29T17:42:23.000Z","dependencies_parsed_at":"2023-12-11T07:11:55.894Z","dependency_job_id":null,"html_url":"https://github.com/AlienCreations/node-authenticator","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/AlienCreations%2Fnode-authenticator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlienCreations%2Fnode-authenticator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlienCreations%2Fnode-authenticator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlienCreations%2Fnode-authenticator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlienCreations","download_url":"https://codeload.github.com/AlienCreations/node-authenticator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253166523,"owners_count":21864482,"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-06T10:13:47.161Z","updated_at":"2025-05-09T00:12:52.932Z","avatar_url":"https://github.com/AlienCreations.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-authenticator\nAuthentication utility for Alien Creations node apps.\n\n## Install\n\n```\n$ yarn add @aliencreations/node-authenticator\n```\n\n## Tenancy Permissions\nThis library comes with an `ensureAuthorized` ExpressJS middleware, which depends\non `req.tenant.id` and `req.tenantOrganization.id` to have been set by the previous middleware.\n\n## `authenticator` Usage\n```js\n'use strict';\n\nconst R        = require('ramda'),\n      config   = require('config'),\n      apiUtils = require('alien-node-api-utils'),\n      passport = require('passport');\n\nconst { authenticator } = require('@aliencreations/node-authenticator')('jwt');\n\nconst CLOUD_USER_AUTH_STRATEGY = {\n  strategy : 'cloudUser',\n  alg      : 'RS256',\n  key      : 'authPlatform',\n  aud      : 'authPlatform'\n};\n\nconst commonJwtOptions       = R.path(['auth', 'jwtOptions'],         config),\n      authTokenProfileFields = R.path(['auth', 'tokenProfileFields'], config);\n\nconst mergeProfileWithStrategyIdentifier = R.compose(\n  R.mergeDeepRight(CLOUD_USER_AUTH_STRATEGY),\n  R.prop('profile')\n);\n\nconst login = (req, res) =\u003e {\n  const MASTER_PRIVATE_KEY = process.env.PRIVATE_KEY.replace(/\\\\n/g, '\\n');\n\n  passport.authenticate('local', (err, user) =\u003e {\n    if (err) {\n      return apiUtils.jsonResponseError(req, res, config.errors.decorateForJson(err));\n    }\n    if (!user) {\n      return apiUtils.jsonResponseError(req, res, config.errors.decorateForJson(R.path(['errors', 'db', 'NO_QUERY_RESULTS'], config)));\n    }\n\n    const payload = mergeProfileWithStrategyIdentifier(user),\n          secret  = MASTER_PRIVATE_KEY;\n\n    authenticator.sign(payload, secret, commonJwtOptions)\n      .then(token =\u003e {\n        const refreshToken = authenticator.generateAndCacheRefreshToken({ payload, secret });\n\n        res.set('x-auth-token',    token);\n        res.set('x-refresh-token', refreshToken);\n        res.set('x-profile',       JSON.stringify(payload));\n\n        return apiUtils.jsonResponseSuccess(req, res, R.pick(authTokenProfileFields, user.profile));\n      })\n      .catch(err =\u003e apiUtils.jsonResponseError(req, res, config.errors.decorateForJson(err)));\n\n  })(req, res, R.T);\n\n};\n\nmodule.exports = login;\n\n```\n\n## `ensureAuthorized` Middleware Usage\n```js\nconst { ensureAuthorized } = require('@aliencreations/node-authenticator')('jwt');\n\nrouter.get('/some/route/:id', ensureAuthorized, (req, res) =\u003e {\n  // Do stuff that requires an authenticated user.\n});\n```\n\n---\n## Changelog\n\n##### 1.0.0\n  - Initial commit.\n\n##### 1.0.1\n  - Add support for deleteRefreshToken\n\n##### 1.0.2\n  - Add support for refreshToken renewal\n\n##### 1.1.0\n  - Replace `id` with `uuid` support throughout for `cloudUser` / `tenant` / `tenantOrganization`\n\n##### 1.1.1\n  - Update `node-error`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faliencreations%2Fnode-authenticator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faliencreations%2Fnode-authenticator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faliencreations%2Fnode-authenticator/lists"}