{"id":17952622,"url":"https://github.com/lahirumaramba/edge_token_verifier","last_synced_at":"2025-04-03T16:27:07.788Z","repository":{"id":65593677,"uuid":"593017119","full_name":"lahirumaramba/edge_token_verifier","owner":"lahirumaramba","description":"Experimental token verifier that works on the Edge","archived":false,"fork":false,"pushed_at":"2023-01-29T17:50:45.000Z","size":138,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T02:01:55.530Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lahirumaramba.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":"2023-01-25T02:46:56.000Z","updated_at":"2023-06-24T03:52:52.000Z","dependencies_parsed_at":"2023-02-16T00:10:41.198Z","dependency_job_id":null,"html_url":"https://github.com/lahirumaramba/edge_token_verifier","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lahirumaramba%2Fedge_token_verifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lahirumaramba%2Fedge_token_verifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lahirumaramba%2Fedge_token_verifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lahirumaramba%2Fedge_token_verifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lahirumaramba","download_url":"https://codeload.github.com/lahirumaramba/edge_token_verifier/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247035929,"owners_count":20872859,"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-10-29T09:58:49.172Z","updated_at":"2025-04-03T16:27:07.773Z","avatar_url":"https://github.com/lahirumaramba.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# edge_token_verifier\n\n**Experimental token verifier that works on the Edge.**\n\nHello there! This is an early stage experimental Deno module to verify tokens on\nedge runtimes. We are also experimenting with\n[`dnt`](https://github.com/denoland/dnt) to create the the Node.js compatible\nmodule.\n\nWe are currently testing the module on different edge runtimes. The current\nreleases are only for testing purposes.\n\n```js\nimport { AppCheckTokenVerifier } from 'https://deno.land/x/edge_token_verifier@v0.2.0/mod.ts';\n```\n\n## Node.js\n\n```js\nimport { AppCheckTokenVerifier } from '@lahirumaramba/edge-token-verifier';\n```\n\n# Examples on the Edge\n\n## Netlify Edge Functions\n\n```js\n// examples/netlify-edge/netlify/edge-functions/hello.ts\nimport { AppCheckTokenVerifier } from 'https://deno.land/x/edge_token_verifier@v0.2.0/mod.ts';\n\nexport default async (request: Request) =\u003e {\n  const appCheckToken = request.headers.get('X-Firebase-AppCheck');\n  const appCheckClaims = await verifyAppCheckToken(appCheckToken);\n\n  if (!appCheckClaims) {\n    return Response.json(\n      { message: 'Unauthorized access. Invalid App Check token.' },\n      { status: 401, headers: { \"content-type\": \"application/json\" } },\n    );\n  }\n  return new Response(`Hello world Netlify Edge: App:${appCheckClaims.app_id}`);\n};\n\nconst tokenVerifier = new AppCheckTokenVerifier();\nconst verifyAppCheckToken = async (appCheckToken: string | null) =\u003e {\n  if (!appCheckToken) {\n    return null;\n  }\n  try {\n    return await tokenVerifier.verify(appCheckToken, 'project-id');\n  } catch (_err) {\n    return null;\n  }\n};\n\nexport const config = { path: '/api' };\n```\n\n## Vercel Edge Functions (Next.js Middleware)\n\n```js\n// examples/edge-token-vc/middleware.ts\nimport { NextResponse } from 'next/server';\nimport type { NextRequest } from 'next/server';\nimport { AppCheckTokenVerifier } from '@lahirumaramba/edge-token-verifier';\n\nexport async function middleware(request: NextRequest) {\n  const verifyAppCheckToken = async (appCheckToken: string | null) =\u003e {\n    if (!appCheckToken) {\n      return null;\n    }\n    const tokenVerifier = new AppCheckTokenVerifier();\n    try {\n      return await tokenVerifier.verify(appCheckToken, 'project-id');\n    } catch (_err) {\n      return null;\n    }\n  };\n  const appCheckToken = request.headers.get('X-Firebase-AppCheck');\n  const appCheckClaims = await verifyAppCheckToken(appCheckToken);\n\n  if (!appCheckClaims) {\n    return NextResponse.json(\n      { message: 'Unauthorized access. Invalid App Check token.' },\n      { status: 401, headers: { 'content-type': 'application/json' } },\n    );\n  }\n  return NextResponse.next();\n}\n\nexport const config = {\n  matcher: '/api/hello/:path*',\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flahirumaramba%2Fedge_token_verifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flahirumaramba%2Fedge_token_verifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flahirumaramba%2Fedge_token_verifier/lists"}