{"id":13789803,"url":"https://github.com/eelkevdbos/elysia-basic-auth","last_synced_at":"2026-01-21T17:05:24.662Z","repository":{"id":193936251,"uuid":"686723763","full_name":"eelkevdbos/elysia-basic-auth","owner":"eelkevdbos","description":"Basic auth plugin for Elysiajs","archived":false,"fork":false,"pushed_at":"2025-01-17T16:07:04.000Z","size":48,"stargazers_count":18,"open_issues_count":2,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-08T15:49:14.316Z","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/eelkevdbos.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-09-03T18:27:13.000Z","updated_at":"2025-03-09T20:53:39.000Z","dependencies_parsed_at":"2023-10-10T15:44:30.386Z","dependency_job_id":"ebd73d80-8853-41c8-aade-f31fb0f3b6e4","html_url":"https://github.com/eelkevdbos/elysia-basic-auth","commit_stats":null,"previous_names":["eelkevdbos/elysia-basic-auth"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/eelkevdbos/elysia-basic-auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eelkevdbos%2Felysia-basic-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eelkevdbos%2Felysia-basic-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eelkevdbos%2Felysia-basic-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eelkevdbos%2Felysia-basic-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eelkevdbos","download_url":"https://codeload.github.com/eelkevdbos/elysia-basic-auth/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eelkevdbos%2Felysia-basic-auth/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28636751,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T15:01:31.228Z","status":"ssl_error","status_checked_at":"2026-01-21T14:42:58.942Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":[],"created_at":"2024-08-03T22:00:33.300Z","updated_at":"2026-01-21T17:05:24.636Z","avatar_url":"https://github.com/eelkevdbos.png","language":"TypeScript","readme":"Elysia Basic Auth ![example workflow](https://github.com/eelkevdbos/elysia-basic-auth/actions/workflows/test.yml/badge.svg)\n===\n\nBasic auth for [Elysia.js](https://elysiajs.com/).\n\n- Uses the `request` event to handle authentication, decoupling authentication from route existence, limiting url [fuzzing](https://owasp.org/www-project-web-security-testing-guide/latest/6-Appendix/C-Fuzzing) exposure.\n- Compares credentials timing-attack safely via `crypto.timingSafeEqual`.\n- Exposes the authenticated realm via `store.basicAuthRealm`.\n- Optionally, bypasses CORS preflight requests, blocks them by default (in scope).\n- Loads credentials from:\n  - A list of `{username, password}` objects.\n  - A file containing `username:password` pairs, separated by `newlines`.\n  - An environment variable containing `username:password` pairs, separated by `semicolons`.\n\nFuture releases may include:\n- Support for hashed passwords.\n\nInstall\n---\n\n```\nbun add @eelkevdbos/elysia-basic-auth\n```\n\nUsage\n---\n\nCheck out full samples at [`examples`](./examples/) or check out the tests [`tests`](src/index.test.ts).\n\n```ts\nimport { Elysia } from 'elysia'\nimport { basicAuth } from '@eelkevdbos/elysia-basic-auth'\n\nprocess.env[\"BASIC_AUTH_CREDENTIALS\"] = \"admin:admin;user:user\"\n\nnew Elysia()\n  .use(basicAuth())\n  // all routes are protected by default\n  .get(\"/\", () =\u003e \"private\")\n  // access to realm within a handler\n  .get('/private/realm-stored', ({ store }) =\u003e store.basicAuthRealm)\n  .listen(3000)\n```\n\nConfiguration\n---\n\n### credentials\n\n`{ file: string } | { env: string } | { username: string, password: string }[]`\n\nA list of credentials valid for authentication, a file with credential pairs separated by newlines, or an environment variable with credential pairs separated by semicolons.\n\nDefault: `{ env: \"BASIC_AUTH_CREDENTIALS\" }`\n\n### header\n\n`string`\n\nDefault: `Authorization`\n\nHeader used for basic authentication.\n\n### realm\n\n`string`\n\nDefault: `Secure Area`\n\nRealm used for basic authentication\n\n### unauthorizedMessage\n\n`string`\n\nDefault: `Unauthorized`\n\nResponse body for unauthorized requests\n\n### unauthorizedStatus\n\n`number`\n\nDefault: `401`\n\nResponse status for unauthorized requests\n\n### scope\n\n`string | string[] | (ctx: PreContext) =\u003e boolean`\n\nDefault: `/`\n\nA string or list of strings that will be compared with the current request path via `startsWith`.\n\nAlternatively, a function can be provided that returns `true` if the context (and thereby request) is in the scope of the current basic auth protection space.\n\n### skipCorsPreflight\n\n`boolean`\n\nDefault: `false`\n\nA boolean that determines whether CORS preflight requests should be skipped.\n\n### enabled\n\n`boolean`\n\nDefault: `true`\n\nA boolean that determines whether basic auth should be enabled. If set to `false`, will disable the `onRequest` handler.\n","funding_links":[],"categories":["Plugins"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feelkevdbos%2Felysia-basic-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feelkevdbos%2Felysia-basic-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feelkevdbos%2Felysia-basic-auth/lists"}