{"id":16672603,"url":"https://github.com/hankei6km/gas-github-app-token","last_synced_at":"2025-04-09T20:00:28.015Z","repository":{"id":36974633,"uuid":"476350405","full_name":"hankei6km/gas-github-app-token","owner":"hankei6km","description":"GitHub App の Access Token 取得をサポートする Google Apps Script のライブラリー。","archived":false,"fork":false,"pushed_at":"2024-04-09T16:04:30.000Z","size":1455,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-04-09T19:39:06.555Z","etag":null,"topics":["github","githubapp","googleappsscript","token"],"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/hankei6km.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}},"created_at":"2022-03-31T14:48:09.000Z","updated_at":"2024-04-15T07:01:12.726Z","dependencies_parsed_at":"2023-11-06T05:28:56.777Z","dependency_job_id":"39ecad1c-91c0-4aea-80ff-c4a4e8009356","html_url":"https://github.com/hankei6km/gas-github-app-token","commit_stats":{"total_commits":144,"total_committers":2,"mean_commits":72.0,"dds":"0.13194444444444442","last_synced_commit":"234d66ea7a21e7b75a2f199710dab76d75f79cf6"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":"hankei6km/my-starter-gas-lib-ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hankei6km%2Fgas-github-app-token","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hankei6km%2Fgas-github-app-token/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hankei6km%2Fgas-github-app-token/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hankei6km%2Fgas-github-app-token/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hankei6km","download_url":"https://codeload.github.com/hankei6km/gas-github-app-token/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103877,"owners_count":21048245,"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":["github","githubapp","googleappsscript","token"],"created_at":"2024-10-12T12:06:47.990Z","updated_at":"2025-04-09T20:00:27.962Z","avatar_url":"https://github.com/hankei6km.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gas-github-app-token\n\nGitHub App の Access Token 取得をサポートする Google Apps Script のライブラリー。\n\n## Setup\n\nライブラリーは App Script で利用できる状態になっています。\nApps Script のコードエディターで以下の手順を実行するとプロジェクトへ追加できます。\n\n1. コードエディターのファイル名一覧が表示される部分の「ライブラリ +」をクリック\n1. 「スクリプト ID」フィールドに `1S3DNbJEq91TAWt753wnEnDtUNcnWWBVSUl7_mNiyzi1rc9BwButo07xl` を入力し検索をクリック\n1. バージョンを選択(通常は最新版)\n1. 「ID」を `GitHubAppToken` へ変更\n1. 「追加」をクリック\n\n上記以外にも Release ページから `gas-github-app-token.zip` をダウンロードし、`/dist` ディレクトリーをプロジェクトへコピーできます。\n\n## Usage\n\nGoogle Apps Script のスクリプトから GitHub App のプライベートキーを利用して Access Token を取得する方法です。\n\n### Convert private key\n\nGitHub からダウンロードしたプライベートキーは Google Apps Script の `Utilities.computeRsaSha256Signature()` では扱えません。そのため、以下の方法で変換します(`xxxxx-private-key.pem` をダウンロードしたファイルに置き換えてください)。\n\n```console\n$ openssl pkcs8 -topk8 -inform pem -in xxxxx-private-key.pem -outform pem -nocrypt -out new-private.pem\n```\n\n### Properties\n\n以下の項目をスクリプトから参照できる場所(スクリプトプロパティーなど)に保存します。\n\n- App ID - GitHub App のアプリケーション ID\n- Installation ID - インストールされた GitHub App へ付与されている ID\n- Private Key - 上記で変換したプライベートキー\n\n### Code\n\nApp Id などをスクリプトプロパティーへ保存している場合のサンプルです。\n\n```js\nfunction main() {\n  const props = PropertiesService.getScriptProperties()\n  const appId = props.getProperty('appId')\n  const installationId = props.getProperty('installationId')\n  const privateKey = props.getProperty('privateKey')\n\n  // Generate URL and options to UrlFetchApp.fetch()\n  const [url, opts] = GitHubAppToken.generate({\n    appId,\n    installationId,\n    privateKey\n  })\n\n  // Fetch token\n  const res = UrlFetchApp.fetch(url, opts)\n  console.log(JSON.parse(res.getContentText())) // { token: 'xxxxxx', }\n}\n```\n\n## TypeScript\n\nTypeScript(clasp) でコードを記述している場合は、以下の方法で型定義を設定できます。\n\n型定義パッケージをインストールします。\n\n```console\n$ npm install --save-dev  @hankei6km/gas-github-app-token\n```\n\n`tsconfig.json` に定義を追加します。\n\n```json\n{\n  \"compilerOptions\": {\n    \"target\": \"ES2019\",\n    \"module\": \"ES2020\",\n    \"lib\": [\"ESNext\"],\n    \"types\": [\"@types/google-apps-script\", \"@hankei6km/gas-github-app-token\"]\n  }\n}\n```\n\n## License\n\nMIT License\n\nCopyright (c) 2022 hankei6km\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhankei6km%2Fgas-github-app-token","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhankei6km%2Fgas-github-app-token","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhankei6km%2Fgas-github-app-token/lists"}