{"id":26229589,"url":"https://github.com/miklevin/ohawf","last_synced_at":"2025-04-19T18:53:40.413Z","repository":{"id":57448446,"uuid":"345754519","full_name":"miklevin/ohawf","owner":"miklevin","description":"The easiest Google OAuth2 you ever did see.","archived":false,"fork":false,"pushed_at":"2023-01-04T22:24:05.000Z","size":472,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-17T12:48:24.502Z","etag":null,"topics":["nbdev","oauth","oauth2","oauth2-authentication"],"latest_commit_sha":null,"homepage":"http://miklevin.github.io/ohawf/","language":"JavaScript","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/miklevin.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":"2021-03-08T18:25:42.000Z","updated_at":"2024-07-18T19:30:41.000Z","dependencies_parsed_at":"2023-02-02T22:01:31.285Z","dependency_job_id":null,"html_url":"https://github.com/miklevin/ohawf","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"fastai/nbdev_template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miklevin%2Fohawf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miklevin%2Fohawf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miklevin%2Fohawf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miklevin%2Fohawf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/miklevin","download_url":"https://codeload.github.com/miklevin/ohawf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249770055,"owners_count":21323067,"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":["nbdev","oauth","oauth2","oauth2-authentication"],"created_at":"2025-03-12T22:16:54.129Z","updated_at":"2025-04-19T18:53:40.382Z","avatar_url":"https://github.com/miklevin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"ohawf\n================\n\n\u003c!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! --\u003e\n\n## Install\n\n``` sh\npip install -U ohawf\n```\n\nAre you trying to log into Google Analytics, Search Console, or even\nGoogle Photos from a Jupyter Notebook? Does all the advice telling you\nto register as a\n\u003ca href=\"https://console.cloud.google.com/\"\u003edeveloper\u003c/a\u003e and the\nmangled [Google\nexamples](https://developers.google.com/webmaster-tools/search-console-api-original/v3/quickstart/quickstart-python)\nhave you frustrated? Well then, ***ohawf*** is for you.\n\n## How to use\n\n``` python\nimport ohawf\n\ncreds = ohawf.get()\n```\n\n### Why So Easy?\n\nGoogle OAuth2 woes go away once you can use the authentication scheme\nthat pops up the same **“login as Google”** web-prompt that all Mobile\nand Web apps seem to be using these days. It doesn’t seem possible, but\nthis authentication scheme actually works from a Jupyter Notebook in\nJupyterLab.\n\nOhawf makes JupyterLab behave like an installed app, so that when you\nfirst run **creds= ohawf.get()**, you’ll be presented with the “Login\nwith Google” prompt. Just just wait a moment, it will pop up a window\nseparate from JupyterLab’s own, and let you log in then prompt you to\nclose the window. If not, \u003ca href=\"https://mikelev.in/ux\"\u003eDrink Me\u003c/a\u003e.\n\n### A Tale of 2 Installed App Flows\n\nWhat makes ohawf work is this line:\n\n``` python\nfrom google_auth_oauthlib.flow import InstalledAppFlow\n```\n\n#### The Old Way: Copy/Paste Token\n\nInstalledAppFlow’s ***run_console()*** prompts you to copy/paste a token\nfrom a browser tab to Jupyter and used to work well, but that approach\nhas been deprecated. It can still be forced to work, but it’s not so\neasy.\n\n#### The New Way: Gotta Have a Webserver\n\nThe new way which is now the ohawf default is ***run_local_server()***.\nThis is what you encounter all the time with mobile apps when you see\n“Login with Google”. An embedded browser pops up, goes through login,\nthen returns you to the mobile app. This works in Jupyter too. If you\nhave problems, run Jupyter \u003ca href=\"https://mikelev.in/ux/\"\u003ethis\nway\u003c/a\u003e. And if you need to force ohawf to use run_console() for a\nserver installation, you can do this:\n\n``` python\nimport ohawf\ncreds = ohawf.get(cli=True)\n```\n\nBut then you’ll have to whitelist your email address, and you can only\ndo that through the [Google Cloud\nConsole](https://console.cloud.google.com/) so chicken-and-egg. If you\nhave to go that route, consider just registering as a Google developer\nand downloading a OAuth Client secret json file like this:\n\n- Go to \u003chttps://console.cloud.google.com\u003e\n- Make sure you’re in the correct Google account.\n- Create a new Project.\n- Go to API \u0026 Services.\n- Enable the APIs \u0026 Services you want to use.\n- Go to Credentials.\n- Create a new OAuth 2.0 Client IDs of the Desktop App type.\n- Go to OAuth consent screen and set it up.\n- Go to +Add users, under test users (gets around tight security)\n- Add the users for the test (your gmail, necessary even though already\n  the app owner)\n- Go back to Credentials and download OAuth Client.\n  - Typically,\n    ***client_secret\\_\\[secret\\].apps.googleusercontent.com.json***\n- Use that file with ohawf\n\nOnce you have the Client Secret JSON file, you can call ohawf like this:\n\n``` python\nimport ohawf\n\ncreds = ohawf.get(file=\"client_secret.json\")\n```\n\n### Adding Scopes\n\nThe ohawf package uses the following default scopes if you don’t set\nany:\n\n    https://www.googleapis.com/auth/spreadsheets\n    https://www.googleapis.com/auth/gmail.modify\n    https://www.googleapis.com/auth/userinfo.email\n    https://www.googleapis.com/auth/youtube.readonly\n    https://www.googleapis.com/auth/analytics.readonly\n    https://www.googleapis.com/auth/webmasters.readonly\n    https://www.googleapis.com/auth/yt-analytics.readonly\n    https://www.googleapis.com/auth/photoslibrary.readonly\n\nIf you want to set your own scopes, create a Python list of scopes and\nfeed it to ohawf:\n\n``` python\nscopes = [\"https://www.googleapis.com/auth/spreadsheets\"]\ncreds = ohawf(scopes=scopes)\n```\n\n## Google Services\n\n    from apiclient.discovery import build\n\nConnect to Google services by giving ***build*** any (activated) API\nname, version and credentials such listing your GSC sites:\n\n    gsc_service = build('searchconsole', 'v1', credentials=cred)\n    gsc_sites = gsc_service.sites().list().execute()\n    [print(x['siteUrl']) for x in gsc_sites['siteEntry']];\n\n…or this go list your GA accounts:\n\n    ga_service = build('analytics', 'v3', credentials=cred)\n    ga_accounts = ga_service.management().accounts().list().execute()\n    [print((x['id'], x['name'])) for x in ga_accounts['items']];\n\n## Copyright (c) 2023 Mike Levin\n\nPermission is hereby granted, free of charge, to any person obtaining a\ncopy of this software and associated documentation files (the\n“Software”), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be included\nin all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS\nOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n# Privacy Policy\n\n## Last updated: December 31, 2022\n\nThis app does not collect nor use any of Your Personal data.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiklevin%2Fohawf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiklevin%2Fohawf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiklevin%2Fohawf/lists"}