{"id":19410022,"url":"https://github.com/metadream/deno-google","last_synced_at":"2025-04-12T08:44:12.877Z","repository":{"id":144612511,"uuid":"608608955","full_name":"metadream/deno-google","owner":"metadream","description":"An easy way to access Google Drive without any external dependencies.","archived":false,"fork":false,"pushed_at":"2024-02-24T07:20:35.000Z","size":9,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-23T02:03:22.180Z","etag":null,"topics":["deno","google-apis","google-drive"],"latest_commit_sha":null,"homepage":"https://deno.land/x/google","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/metadream.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-03-02T11:25:07.000Z","updated_at":"2024-12-18T20:37:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"b2fa64a4-8061-4822-8ad7-68f836c70a0e","html_url":"https://github.com/metadream/deno-google","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/metadream%2Fdeno-google","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metadream%2Fdeno-google/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metadream%2Fdeno-google/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metadream%2Fdeno-google/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/metadream","download_url":"https://codeload.github.com/metadream/deno-google/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248543825,"owners_count":21121837,"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":["deno","google-apis","google-drive"],"created_at":"2024-11-10T12:14:38.003Z","updated_at":"2025-04-12T08:44:12.872Z","avatar_url":"https://github.com/metadream.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Deno-Google\n\n## Drive\n\nAn easy way to access Google Drive without any external dependencies.\n\n```ts\nimport { GoogleDrive } from \"https://deno.land/x.google/drive.ts\";\n\nconst gd = new GoogleDrive({\n  client_id: \"xxxxx-xxxxxxxxxxxxxx.apps.googleusercontent.com\",\n  client_secret: \"xxxxxxxxxxxxxxx\",\n  refresh_token: \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\n  logger: false,\n});\n\ntry {\n  // This step can be omitted, and it will reauthorize when requesting data\n  await gd.authorize();\n  // The default value of the path is \"root\"\n  const metadata = await gd.index(\"your/path\");\n\n  if (metadata.isFolder) {\n    console.log(metadata.list());\n  } else {\n    // handle metadata.raw() or metadata.raw(range)\n  }\n} catch (e) {\n  console.log(e);\n}\n```\n\n## OAuth\n\nThis class is a simplification of the google oauth2 authorization flow.\n\n### 1. Create an instance\n\n```ts\nimport { GoogleOAuth } from \"https://deno.land/x/google/oauth.ts\";\n\nconst ga = new GoogleOAuth({\n  client_id: \"xxxxx-xxxxxxxxxxxxxx.apps.googleusercontent.com\",\n  client_secret: \"xxxxxxxxxxxxxxx\",\n  redirect_uri: \"http://example.com/redirect_uri\",\n  \"scopes\": [\n    \"https://www.googleapis.com/auth/userinfo.email\",\n    \"https://www.googleapis.com/auth/drive.readonly\",\n  ],\n});\n\nconst link = ga.buildAuthLink();\n```\n\n### 2. Visit the link\n\nAfter clicking the link to complete the authorization, it will redirect to the\nuri with the \"code\" parameter. You can receive the \"code\" in redirect_uri.\n\n### 3. Get tokens\n\n```ts\n// tokens include refresh_token, access_token, id_token, etc.\n// But the access_token has an expiry time, so you need to get it again through the next step\nconst tokens = await ga.getTokens(code);\n```\n\n### 4. Get access_token\n\n```ts\n// refresh_token is obtained in the previous step, it is permanently valid.\nconst accessToken = ga.getAccessToken(refresh_token);\n```\n\n### 5. Decode id_token (without verifiy signature)\n\nThe id_token obtained in the third step contains some personal information of\nthe google account, you can decode it.\n\n```ts\nconst data = ga.decodeIdToken(id_token);\n// it will return { header, payload, signature }\n// payload is the personal information\n```\n\n### 6. Decode id_token (verify signature via CERTS_URL)\n\nIt is usually not necessary to verify the signature for the first authorization,\nbut it is strongly recommended to verify when you use the id_token as a cookie\nto keep the login state.\n\n**NOTE: There is a bug in this method, which is caused by the type of\n\"cryptoKey\", and I don't know how to solve it for the time being.**\n\n```ts\nconst data = await ga.verifyIdToken(id_token);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetadream%2Fdeno-google","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmetadream%2Fdeno-google","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetadream%2Fdeno-google/lists"}