{"id":16720219,"url":"https://github.com/jorgevrgs/sails-hook-jwtoken","last_synced_at":"2026-05-21T10:04:56.715Z","repository":{"id":48962354,"uuid":"275899750","full_name":"jorgevrgs/sails-hook-jwtoken","owner":"jorgevrgs","description":"jsonwebtoken hook for Sails.js v1","archived":false,"fork":false,"pushed_at":"2023-07-27T17:20:23.000Z","size":2301,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-11T13:36:53.135Z","etag":null,"topics":["javascript","jsonwebtoken","jwt","nodejs","sailsjs"],"latest_commit_sha":null,"homepage":"","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/jorgevrgs.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-06-29T18:50:25.000Z","updated_at":"2023-02-11T03:44:06.000Z","dependencies_parsed_at":"2025-03-15T11:50:50.959Z","dependency_job_id":null,"html_url":"https://github.com/jorgevrgs/sails-hook-jwtoken","commit_stats":null,"previous_names":["jorgevrgs/sails-hook-jsonwebtoken"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/jorgevrgs/sails-hook-jwtoken","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorgevrgs%2Fsails-hook-jwtoken","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorgevrgs%2Fsails-hook-jwtoken/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorgevrgs%2Fsails-hook-jwtoken/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorgevrgs%2Fsails-hook-jwtoken/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jorgevrgs","download_url":"https://codeload.github.com/jorgevrgs/sails-hook-jwtoken/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorgevrgs%2Fsails-hook-jwtoken/sbom","scorecard":{"id":532966,"data":{"date":"2025-08-11","repo":{"name":"github.com/jorgevrgs/sails-hook-jwtoken","commit":"c9fb1fbf5630894fb15483ab0480644e929e2a44"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.8,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/4 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql-analysis.yml:28","Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql-analysis.yml:29","Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1","Warn: no topLevel permission defined: .github/workflows/npm-publish.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":2,"reason":"dependency not pinned by hash detected -- score normalized to 2","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/jorgevrgs/sails-hook-jwtoken/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:45: update your workflow using https://app.stepsecurity.io/secureworkflow/jorgevrgs/sails-hook-jwtoken/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:59: update your workflow using https://app.stepsecurity.io/secureworkflow/jorgevrgs/sails-hook-jwtoken/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:72: update your workflow using https://app.stepsecurity.io/secureworkflow/jorgevrgs/sails-hook-jwtoken/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/jorgevrgs/sails-hook-jwtoken/npm-publish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/jorgevrgs/sails-hook-jwtoken/npm-publish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/jorgevrgs/sails-hook-jwtoken/npm-publish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/jorgevrgs/sails-hook-jwtoken/npm-publish.yml/master?enable=pin","Info:   0 out of   8 GitHub-owned GitHubAction dependencies pinned","Info:   2 out of   2 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":7,"reason":"SAST tool detected but not run on all commits","details":["Info: SAST configuration detected: CodeQL","Warn: 0 commits out of 30 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"28 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25","Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-ghr5-ch3p-vcr6","Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc","Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-75v8-2h7p-7m2m","Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5","Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55","Warn: Project is vulnerable to: GHSA-76c9-3jph-rj3q","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-35q2-47q7-3pc3","Warn: Project is vulnerable to: GHSA-gpw9-fwm8-7rx7","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg","Warn: Project is vulnerable to: GHSA-76p7-773f-r4q5","Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-qgmg-gppg-76g5","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-20T06:11:29.793Z","repository_id":48962354,"created_at":"2025-08-20T06:11:29.793Z","updated_at":"2025-08-20T06:11:29.793Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33297172,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-21T02:57:32.698Z","status":"ssl_error","status_checked_at":"2026-05-21T02:57:31.990Z","response_time":62,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["javascript","jsonwebtoken","jwt","nodejs","sailsjs"],"created_at":"2024-10-12T22:06:15.637Z","updated_at":"2026-05-21T10:04:56.680Z","avatar_url":"https://github.com/jorgevrgs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sails-hook-jwtoken - jsonwebtoken hook for Sails.js v1\n\n## Installation\n\n```\nnpm i sails-hook-jwtoken\n```\n\n![npm](https://img.shields.io/npm/v/sails-hook-jwtoken?style=for-the-badge)\n\n![Travis (.org)](https://img.shields.io/travis/jorgevrgs/sails-hook-jwtoken?style=for-the-badge)\n\n[![Node.js Package](https://github.com/jorgevrgs/sails-hook-jwtoken/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/jorgevrgs/sails-hook-jwtoken/actions/workflows/npm-publish.yml)\n\n## How to use\n\n### sails.helpers.jwt.sign(payload) Generate your token\n\n```js\n// api/controller/entrance/login\n...\nconst jwtToken = await sails.helpers.jwt.sign({\n  sub: userRecord.id,\n});\n\nreturn jwtToken;\n```\n\n### sails.helpers.jwt.verify(req, res) Verify token\n\nBy default the module include a validation hook for the authorization header, however the user could disable the default and implement a custom one with the configuration set to `sails.config.jwt.enableRequestHook = false`.\n\n### Process your `req.me` object\n\nThe hook expose `req.me` to be used either in a controller or a policy. However, the user is able to disable this hook to implement one manually with the option `sails.config.jwt.enableRequestHook = false` in the configuration.\n\n## Configuration\n\nThere are a couple of options to configure a Json Web Token signature, either with a private/public string or a private/public key file.\n\nDefault configuration:\n\n```js\nmodule.exports.jwt: {\n  model: 'user',\n  privateFile: false,\n  publicFile: false,\n  privateFileName: 'private',\n  publicFileName: 'public',\n  ext: '.pem',\n  passphrase: '',\n  privateKey: 'super-secret-string',\n  publicKey: 'super-secret-string',\n  enableRequestHook: true,\n  signOptions: {\n    algorithm: 'HS256',\n    expiresIn: '7d',\n  },\n  verifyOptions: {\n    algorithms: ['HS256'],\n  },\n},\n```\n\n### String Configuration\n\nExample:\n\n```js\n// config/jwt.js\n\nmodule.exports.jwt: {\n  privateKey: 'an-impoved-super-secret-string',\n  publicKey: 'an-impoved-super-secret-string',\n},\n\n```\n\n### File Configuration\n\nExample:\n\n```js\n// config/jwt.js\n\nmodule.exports.jwt: {\n  privateFile: true,\n  privateFileName: 'private_passphrase', // Default 'private'\n  publicFile: true,\n  publicFileName: 'public_passphrase', // Default 'public'\n  ext: '.pem', // Default\n  passphrase: 'test' // Default ''\n\n  signOptions: {\n    algorithm: 'RS256',\n    expiresIn: '7d',\n  },\n  verifyOptions: {\n    algorithms: ['RS256'],\n  },\n},\n\n```\n\nWhen use a private/public file, create your files with the `privateFileName`, `publicFileName` and `ext` configuration:\n\nprivate: `config/keys/private.pem`\n\n```\n-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----\n```\n\npublic: `config/keys/public.pem`\n\n```\n-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----\n\n```\n\nCheck this example in StackOverflow to [generate a private / public key](https://stackoverflow.com/questions/40595895/how-can-i-generate-the-private-and-public-certificates-for-jwt-with-rs256-algori).\n\n```\nopenssl genrsa -aes256 -out private.pem 2048\nopenssl rsa -pubout -in private.pem -out public.pem\n```\n\nOr another article [Creating RSA Keys using OpenSSL](https://www.scottbrady91.com/OpenSSL/Creating-RSA-Keys-using-OpenSSL).\n\n```\nopenssl genrsa -out private.pem 2048\nopenssl rsa -in private.pem -pubout -out public.pem\n```\n\n## Example\n\nIf you want to implement your own token verification process, then set configuration `sails.config.jwt.enableRequestHook = false` in the `config/jwt.js` file:\n\n```js\n// config/jwt.js\nmodule.exports.jwt = {\n  ...\n  enableRequestHook: false\n}\n```\n\n### Implement a Policy\n\nRun `sails generate policy check-token`.\n\nCheck the token:\n\n```js\n// api/policies/check-token.js\n// req.authorization = 'Bearer {{token}}'\nmodule.exports = async function (req, res) {\n  const user = await sails.helpers.jwt\n    .verify(req, res, next)\n    .tolerate((err) =\u003e sails.log.silly(err));\n  if (user) {\n    req.me = user;\n  }\n\n  next();\n};\n```\n\nUse the policy in the controllers:\n\n```js\n// config/policies.js\nmodule.exports.policies = {\n  '*': 'is-super-admin',\n  'private/*': ['check-token', 'check-permissions', 'other-policies'],\n  'public/*': true,\n};\n```\n\n### Implement a Hook\n\nRun `sails generate hook check-token`.\n\nCheck the token:\n\n```js\n// api/hooks/check-token/index.js\n// req.authorization = 'Bearer {{token}}'\n...\nroutes: {\n  before: {\n    '/*': {\n      skipAssets: true,\n      fn: async function(req, res, next) {\n        const user = await sails.helpers.jwt.verify(req, res).tolerate((err) =\u003e sails.log.silly(err));\n        if (user) {\n          req.me = user;\n        }\n        next();\n      }\n    }\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjorgevrgs%2Fsails-hook-jwtoken","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjorgevrgs%2Fsails-hook-jwtoken","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjorgevrgs%2Fsails-hook-jwtoken/lists"}