{"id":15775153,"url":"https://github.com/mglagola/hapi-custom-auth","last_synced_at":"2026-05-05T21:35:34.845Z","repository":{"id":57260861,"uuid":"142339241","full_name":"mglagola/hapi-custom-auth","owner":"mglagola","description":"A hapi auth plugin","archived":false,"fork":false,"pushed_at":"2018-07-25T18:39:13.000Z","size":51,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T16:02:39.615Z","etag":null,"topics":["authentication","authorization","hapi","javascript","nodejs","npm"],"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/mglagola.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}},"created_at":"2018-07-25T18:34:07.000Z","updated_at":"2018-07-25T22:57:21.000Z","dependencies_parsed_at":"2022-08-31T12:21:50.111Z","dependency_job_id":null,"html_url":"https://github.com/mglagola/hapi-custom-auth","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/mglagola%2Fhapi-custom-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mglagola%2Fhapi-custom-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mglagola%2Fhapi-custom-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mglagola%2Fhapi-custom-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mglagola","download_url":"https://codeload.github.com/mglagola/hapi-custom-auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246484212,"owners_count":20785031,"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":["authentication","authorization","hapi","javascript","nodejs","npm"],"created_at":"2024-10-04T16:42:33.228Z","updated_at":"2026-05-05T21:35:34.816Z","avatar_url":"https://github.com/mglagola.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hapi Custom Auth\n\nEasy way to create a hapi \"custom\" auth scheme. Looks for value associated with `request.headers.authorization`.\n\n## Usage\n\n##### Install\n\n```\nnpm install --save hapi-custom-auth\n```\n\n##### Configure Server:\n\n```js\nconst HapiCustomAuth = require('hapi-custom-auth');\n// ...\n\nconst AuthSetup = {\n    // See below example\n    plugin: require('./auth-setup');\n}\n\n// ...\n\nconst server = new Hapi.Server(...);\nconst plugins = [\n    // ...\n    HapiCustomAuth,\n    AuthSetup,\n    // ...,\n];\nawait server.register(plugins);\n// ...\n\n```\n\n##### Auth Setup (ex: auth-setup.js)\n\n```js\nconst validate = async (authorization) =\u003e {\n    try {\n        const user = await fakeSQLQuery(`user.token === ${authorization}`);\n        if (!user) return { isValid: false };\n        const credentials = {\n            userId: user.id,\n            scope: [\n                'user',\n                `user-${user.id}`,\n            ],\n        };\n        return { isValid: true, credentials };\n    } catch (error) {\n        return { isValid: false };\n    }\n};\n\nconst isValidToken = (token) =\u003e token \u0026\u0026 token.indexOf('pizza') \u003e= 0;\n\nconst errorFunc = ({ errorType, message, scheme }) =\u003e ({\n    errorType,\n    message,\n    scheme,\n    attributes: { error: 'Invalid token', invalid_token: true },\n});\n\nexports.register = function (server, options) {\n    server.auth.strategy('custom-auth', 'custom-auth', config);\n};\n\nexports.pkg = {\n    name: 'MyAuth',\n    version: '1.0.0',\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmglagola%2Fhapi-custom-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmglagola%2Fhapi-custom-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmglagola%2Fhapi-custom-auth/lists"}