{"id":20764566,"url":"https://github.com/chamini2/hapi-auth-ip-whitelist","last_synced_at":"2025-04-30T08:47:34.205Z","repository":{"id":57260783,"uuid":"95040382","full_name":"chamini2/hapi-auth-ip-whitelist","owner":"chamini2","description":"Hapi.js plugin for authentication scheme of accepting connections only from certain IPs","archived":false,"fork":false,"pushed_at":"2022-12-06T00:41:25.000Z","size":22,"stargazers_count":11,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-12-26T21:11:41.812Z","etag":null,"topics":["hapi-plugin","hapijs","node"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/chamini2.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":"2017-06-21T19:50:53.000Z","updated_at":"2023-11-10T23:59:26.000Z","dependencies_parsed_at":"2023-01-24T07:46:18.687Z","dependency_job_id":null,"html_url":"https://github.com/chamini2/hapi-auth-ip-whitelist","commit_stats":null,"previous_names":[],"tags_count":6,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chamini2%2Fhapi-auth-ip-whitelist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chamini2%2Fhapi-auth-ip-whitelist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chamini2%2Fhapi-auth-ip-whitelist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chamini2%2Fhapi-auth-ip-whitelist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chamini2","download_url":"https://codeload.github.com/chamini2/hapi-auth-ip-whitelist/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225028979,"owners_count":17409614,"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":["hapi-plugin","hapijs","node"],"created_at":"2024-11-17T10:52:44.937Z","updated_at":"2024-11-17T10:52:45.575Z","avatar_url":"https://github.com/chamini2.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hapi-auth-ip-whitelist\n\n[![npm](https://img.shields.io/npm/v/hapi-auth-ip-whitelist.svg)](https://www.npmjs.com/package/hapi-auth-ip-whitelist)\n\n## Usage\n\n### Localhost\n\nOnly accept calls from localhost:\n\n```js\nserver.auth.strategy('localhost', 'ip-whitelist', ['127.0.0.1']);\n```\n\n*NOTE: Third parameter of server.auth.strategy is options which must be an object.* \n\nTo be used like\n\n```js\nserver.route({ \n  method: 'GET', \n  path: '/',\n  handler(request, h) { return \"That was from localhost!\" }, \n  options: { auth: 'localhost' }\n});\n```\n\nIn the route receives a request from a different IP, it will respond a `401 unauthorized` error with the message `192.168.0.102 is not a valid IP`, where `192.168.0.102` is the IP of the request.\n\n### Address ranges\n\nYou can also specify several IPs by passing a list instead. [CIDR](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) notation is supported. \n\nFor example, consider the IPs to expect requests from, as specified by [MercadoPago](https://www.mercadopago.com.co/developers/en/api-docs/basics/design-considerations).\n\n```js\nserver.auth.strategy(\n  'mercado-pago-webhook',\n  'ip-whitelist',\n  ['209.225.49.0/24', '216.33.197.0/24', '216.33.196.0/24', '63.128.82.0/24', '63.128.83.0/24', '63.128.94.0/24']  \n);\n```\n\n\n### Behind proxy\n\nIn case you are behind a proxy, use Hapi plugin `therealyou`.\nIt will find the \"real\" IP in X-Forward headers and modify the request.info.remoteAddress.\n\n```js\nserver.register([\n  {\n    plugin: require('therealyou')\n  },\n  {\n    plugin: require('hapi-auth-ip-whitelist')\n  }\n])\n```\n\n## Example server\n\nStart local example server with\n\n```bash\nnpm start\n```\n\nthen visit [http://localhost:3000](http://localhost:3000).\n\nSuccessfully authenticated request [http://localhost:3000/authenticated](http://localhost:3000/authenticated).\nUnauthenticated request [http://localhost:3000/unauthenticated](http://localhost:3000/unauthenticated).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchamini2%2Fhapi-auth-ip-whitelist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchamini2%2Fhapi-auth-ip-whitelist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchamini2%2Fhapi-auth-ip-whitelist/lists"}