{"id":23925456,"url":"https://github.com/narumincho/apple-notification-jwt","last_synced_at":"2026-05-14T18:32:29.652Z","repository":{"id":270290061,"uuid":"909905463","full_name":"narumincho/apple-notification-jwt","owner":"narumincho","description":"Apple Notification Jwt generator for Deno","archived":false,"fork":false,"pushed_at":"2024-12-30T03:04:09.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-14T18:35:59.060Z","etag":null,"topics":["deno","jwt"],"latest_commit_sha":null,"homepage":"","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/narumincho.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}},"created_at":"2024-12-30T02:59:52.000Z","updated_at":"2024-12-30T03:04:12.000Z","dependencies_parsed_at":"2024-12-30T04:28:10.774Z","dependency_job_id":null,"html_url":"https://github.com/narumincho/apple-notification-jwt","commit_stats":null,"previous_names":["narumincho/apple-notification-jwt"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/narumincho/apple-notification-jwt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/narumincho%2Fapple-notification-jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/narumincho%2Fapple-notification-jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/narumincho%2Fapple-notification-jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/narumincho%2Fapple-notification-jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/narumincho","download_url":"https://codeload.github.com/narumincho/apple-notification-jwt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/narumincho%2Fapple-notification-jwt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33037821,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-14T02:00:06.663Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["deno","jwt"],"created_at":"2025-01-05T20:13:30.788Z","updated_at":"2026-05-14T18:32:29.636Z","avatar_url":"https://github.com/narumincho.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @narumincho/apple-notification-jwt\n\n## Example\n\nGenerate an \"Apple Push Notifications service (APNs)\" key from the\n[Apple Developer Portal](https://developer.apple.com/account/resources/authkeys/list).\n\nYou will download a file containing a private key, such as:\n\n`AuthKey_U7TYW1FV9W.p8`\n\n```\n-----BEGIN PRIVATE KEY-----\nMIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgo72HR/apP7rVzt/D\ndCLcUvzjGvD1pSX5JBrl0pDcK5ihRANCAAQTLLGRWcATb4g7/ie1pHIuhgWGh9dU\nX/0rT6wTZlTm60MWPW+NmrtyR06YwY1T7KH4Sj/wARXGyG9c/frZOo/k\n-----END PRIVATE KEY-----\n```\n\nRemove -----BEGIN PRIVATE KEY-----, -----END PRIVATE KEY-----, and line breaks,\nleaving:\n\n`MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgo72HR/apP7rVzt/DdCLcUvzjGvD1pSX5JBrl0pDcK5ihRANCAAQTLLGRWcATb4g7/ie1pHIuhgWGh9dUX/0rT6wTZlTm60MWPW+NmrtyR06YwY1T7KH4Sj/wARXGyG9c/frZOo/k`\n\nSet this value in the environment variable APPLE_NOTIFICATION_SECRET.\n\n![issAndApnsTopic](./image/issAndApnsTopic.png)\n\nYou can then send notifications using the following code:\n\n```ts\nimport { createAppleNotificationJwt } from \"jsr:@narumincho/apple-notification-jwt\";\n\nconst secret = Deno.env.get(\"APPLE_NOTIFICATION_SECRET\");\nif (!secret) {\n  throw new Error(\"APPLE_NOTIFICATION_SECRET is not found\");\n}\n\nconst jwt = await createAppleNotificationJwt({\n  secret,\n  iat: new Date(),\n  iss: \"FLM12NG8W1\", // Your Apple Developer Team ID\n  kid: \"U7TYW1FV9W\", // Key ID from the generated key\n});\n\nawait fetch(\n  isProduction\n    ? `https://api.push.apple.com:443/3/device/${deviceToken}`\n    : `https://api.development.push.apple.com:443/3/device/${deviceToken}`,\n  {\n    method: \"POST\",\n    headers: {\n      \"apns-topic\": \"com.example.app\",\n      \"apns-push-type\": \"alert\",\n      \"apns-priority\": \"10\",\n      \"apns-expiration\": \"0\",\n      \"content-type\": \"application/json\",\n      authorization: `Bearer ${jwt}`,\n    },\n    body: JSON.stringify({\n      aps: {\n        alert: {\n          title: \"Test Notification\",\n          body: \"This is a test notification.\",\n        },\n      },\n    }),\n  },\n);\n```\n\n### Notes\n\n- Tokens older than 60 minutes cannot be used.\n  [Apple Documentation](https://developer.apple.com/documentation/usernotifications/establishing-a-token-based-connection-to-apns#Refresh-your-token-regularly)\n- Avoid generating multiple tokens within 20 minutes. Reuse existing tokens when\n  possible.\n\n## 例\n\nhttps://developer.apple.com/account/resources/authkeys/list から「Apple Push\nNotifications service (APNs)」を有効にした鍵を生成します\n\n以下のような秘密鍵が含まれたファイルがダウンロードされます\n\n`AuthKey_U7TYW1FV9W.p8`\n\n```\n-----BEGIN PRIVATE KEY-----\nMIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgo72HR/apP7rVzt/D\ndCLcUvzjGvD1pSX5JBrl0pDcK5ihRANCAAQTLLGRWcATb4g7/ie1pHIuhgWGh9dU\nX/0rT6wTZlTm60MWPW+NmrtyR06YwY1T7KH4Sj/wARXGyG9c/frZOo/k\n-----END PRIVATE KEY-----\n```\n\n`-----BEGIN PRIVATE KEY-----`, `-----END PRIVATE KEY-----` と改行を取り除いた\n\n`MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgo72HR/apP7rVzt/DdCLcUvzjGvD1pSX5JBrl0pDcK5ihRANCAAQTLLGRWcATb4g7/ie1pHIuhgWGh9dUX/0rT6wTZlTm60MWPW+NmrtyR06YwY1T7KH4Sj/wARXGyG9c/frZOo/k`\n\nを利用する環境の環境変数 APPLE_NOTIFICATION_SECRET に設定します\n\n![issAndApnsTopic](./image/issAndApnsTopic.png)\n\n以下のようなコードで通知を呼び出せます\n\n```ts\nimport { createAppleNotificationJwt } from \"jsr:@narumincho/apple-notification-jwt\";\n\nconst secret = Deno.env.get(\"APPLE_NOTIFICATION_SECRET\");\nif (!secret) {\n  throw new Error(\"APPLE_NOTIFICATION_SECRET is not found\");\n}\n\nconst jwt = await createAppleNotificationJwt({\n  secret,\n  iat: new Date(),\n  iss: \"FLM12NG8W1\",\n  kid: \"U7TYW1FV9W\",\n});\n\nawait fetch(\n  isProduction\n    ? `https://api.push.apple.com:443/3/device/${deviceToken}`\n    : `https://api.development.push.apple.com:443/3/device/${deviceToken}`,\n  {\n    method: \"POST\",\n    headers: {\n      \"apns-topic\": \"com.example.app\",\n      \"apns-push-type\": \"alert\",\n      \"apns-priority\": \"10\",\n      \"apns-expiration\": \"0\",\n      \"content-type\": \"application/json\",\n      authorization: `Bearer ${jwt}`,\n    },\n    body: JSON.stringify({\n      aps: {\n        alert: {\n          title: \"テスト通知です\",\n          body: \"テスト通知の本文です\",\n        },\n      },\n    }),\n  },\n);\n```\n\n### 注意\n\nhttps://developer.apple.com/documentation/usernotifications/establishing-a-token-based-connection-to-apns#Refresh-your-token-regularly\nに書かれているように\n\n- 60分以上 昔に生成したものは使えません\n- 20分以内に複数のキーを生成するのは避け, 使い回すようにしてください\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnarumincho%2Fapple-notification-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnarumincho%2Fapple-notification-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnarumincho%2Fapple-notification-jwt/lists"}