{"id":16194475,"url":"https://github.com/muniftanjim/gmail-oauth2-script","last_synced_at":"2025-07-19T19:34:59.387Z","repository":{"id":60824054,"uuid":"305173392","full_name":"MunifTanjim/gmail-oauth2-script","owner":"MunifTanjim","description":"Script to get OAuth2 Access Token for Gmail.","archived":false,"fork":false,"pushed_at":"2024-04-16T06:25:16.000Z","size":16,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-02T23:11:13.684Z","etag":null,"topics":["gmail","mbsync","msmtp","mutt","neomutt","oauth2"],"latest_commit_sha":null,"homepage":"","language":"Shell","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/MunifTanjim.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":"2020-10-18T18:51:17.000Z","updated_at":"2024-04-24T08:35:37.000Z","dependencies_parsed_at":"2024-06-09T00:36:27.928Z","dependency_job_id":"7678fdff-68bc-4478-bb40-121dbaab72df","html_url":"https://github.com/MunifTanjim/gmail-oauth2-script","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MunifTanjim/gmail-oauth2-script","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MunifTanjim%2Fgmail-oauth2-script","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MunifTanjim%2Fgmail-oauth2-script/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MunifTanjim%2Fgmail-oauth2-script/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MunifTanjim%2Fgmail-oauth2-script/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MunifTanjim","download_url":"https://codeload.github.com/MunifTanjim/gmail-oauth2-script/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MunifTanjim%2Fgmail-oauth2-script/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265999131,"owners_count":23862219,"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":["gmail","mbsync","msmtp","mutt","neomutt","oauth2"],"created_at":"2024-10-10T08:19:31.456Z","updated_at":"2025-07-19T19:34:59.357Z","avatar_url":"https://github.com/MunifTanjim.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gmail OAuth2 Script\n\nScript to get OAuth2 Access Token for Gmail.\n\nIt can be used with cli tools that interacts with Gmail via\n[IMAP](https://tools.ietf.org/html/rfc3501) or [SMTP](https://tools.ietf.org/html/rfc5321).\nFor example:\n\n- [`mutt`](http://www.mutt.org/) or [`neomutt`](https://neomutt.org/)\n- [`mbsync`](https://isync.sourceforge.io/)\n- [`msmtp`](https://marlam.de/msmtp/)\n- Your own script/tool that speaks IMAP/SMTP\n\n## Installation\n\nJust copy the script you want on your machine and give it executable permission:\n\n```sh\ncurl --progress-bar https://raw.githubusercontent.com/MunifTanjim/gmail-oauth2-script/main/gmail-oauth2_none_none.sh -o ~/.local/bin/gmail-oauth2.sh\nchmod u+x ~/.local/bin/gmail-oauth2.sh\n```\n\nIf you need one, [create an OAuth client](https://console.cloud.google.com/apis/credentials/oauthclient).\nIt is recommented to use \"Desktop app\" as OAuth client type.\n\n## Variants\n\nThere are several variants of the script using different tools for cache, storage or secret management.\n\n### `gmail-oauth2_none_none.sh`\n\nMinimal script with no extra features for caching or secret management.\nIt requires hardcoding sensitive information to the script.\n\n#### Dependencies\n\n- `bash`\n- `jq`\n\n#### Usage\n\n**Get Refresh Token**:\n\n```sh\ngmail-oauth2.sh refresh_token --client-id CLIENT_ID --client-secret CLIENT_SECRET\n```\n\n**Get Access Token**:\n\n```sh\ngmail-oauth2.sh access_token --client-id CLIENT_ID --client-secret CLIENT_SECRET --refresh-token REFRESH_TOKEN\n```\n\n### `gmail-oauth2_bitwarden_secret-tool.sh`\n\nUses Bitwarden during initial setup and GNOME Keyring for the rest.\n\nStore your OAuth2 Client's credentials in a Bitwarden item with the following custom fields:\n\n- `client_id` - OAuth2 Client ID\n- `client_secret` - OAuth2 Client Secret\n\n#### Dependencies\n\n- `bash`\n- `jq`\n- `bw` - [Bitwarden CLI](https://github.com/bitwarden/cli)\n- `secret-tool` - CLI for GNOME Keyring\n\n#### Usage\n\n```sh\ngmail-oauth2.sh \u003cCOMMAND\u003e [ACCOUNT_ID]\n\nCommands:\n  authorize      Perform the initial authorization steps\n  access_token   Prints Access Token\n\nFlags:\n  --account-id   Alias for the Gmail Account         (e.g.: \"personal\" or \"me@example.com\")\n  --store-id     Description for GNOME Keyring Items (default: \"Gmail-OAuth2-Script\")\n  --secret-id    Search Term for Bitwarden Item      (default: \"client.oauth2.com.google.mail\")\n```\n\n**Initial Authorization**:\n\nReads the `client_id` and `client_secret` from Bitwarden, stores them in GNOME Keyring.\nObtains a `refresh_token` after successful authorization and stores it in GNOME Keyring.\n\n```sh\ngmail-oauth2.sh authorize me@example.com\n# or\ngmail-oauth2.sh authorize --account-id me@example.com\n```\n\n**Get Access Token**:\n\nChecks GNOME Keyring for existing `access_token`, if it's not expired prints it.\nOtherwise, get an `access_token` using the `client_id`, `client_secret`, `refresh_token` from GNOME Keyring,\nstores it in GNOME Keyring and prints it.\n\n```sh\ngmail-oauth2.sh access_token --account-id me@example.com\n```\n\n## License\n\nLicensed under the MIT License. Check the [LICENSE](./LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuniftanjim%2Fgmail-oauth2-script","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmuniftanjim%2Fgmail-oauth2-script","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuniftanjim%2Fgmail-oauth2-script/lists"}