{"id":19593135,"url":"https://github.com/felipejfc/django_google_auth","last_synced_at":"2025-07-05T12:37:01.291Z","repository":{"id":68277383,"uuid":"102503699","full_name":"felipejfc/django_google_auth","owner":"felipejfc","description":"A google auth custom authenticator for django that will validate user's access token against google in all requests","archived":false,"fork":false,"pushed_at":"2017-09-21T14:55:15.000Z","size":16,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-27T14:39:28.762Z","etag":null,"topics":["api","dkango","google-authentication","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","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/felipejfc.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":"2017-09-05T16:15:52.000Z","updated_at":"2024-08-29T17:06:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"55fc6561-7a06-4e5a-8bd4-c2e3b27db091","html_url":"https://github.com/felipejfc/django_google_auth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/felipejfc/django_google_auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felipejfc%2Fdjango_google_auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felipejfc%2Fdjango_google_auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felipejfc%2Fdjango_google_auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felipejfc%2Fdjango_google_auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/felipejfc","download_url":"https://codeload.github.com/felipejfc/django_google_auth/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felipejfc%2Fdjango_google_auth/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263743231,"owners_count":23504635,"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":["api","dkango","google-authentication","python"],"created_at":"2024-11-11T08:38:18.516Z","updated_at":"2025-07-05T12:37:01.286Z","avatar_url":"https://github.com/felipejfc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"django-google-auth\n==================\n\nA google auth authenticator backend for django and django rest framework.\nThis backend will validate the user's access token against google in every request, so that when a user has it's email removed from the domain for example, it will lose access instantly.\n\n### Installation\n```\npip install django-google-auth\n```\n\nAdd google_auth to your INSTALLED_APPS\n```\nINSTALLED_APPS = (\n    ...\n    'google_auth',\n)\n```\n\nInclude auth urls to your urls.py\n```\nurlpatterns = patterns(\n    ...\n    (r'^google_auth/', include('google_auth.urls')),\n)\n```\n\nInclude google_auth.authentication.GoogleAuthBackend to AUTHENTICATION_BACKENDS\n```\nAUTHENTICATION_BACKENDS = (\n    ...\n    \"google_auth.authentication.GoogleAuthBackend\",\n)\n```\n\n### Settings\nThe settings of this app are:\n- GOOGLE_AUTH_CLIENT_ID\nthe client id of your google app\n- GOOGLE_AUTH_CLIENT_SECRET\nthe client secret of your google app\n- GOOGLE_AUTH_AUTHORIZED_DOMAINS\nthe email domains that are authorized to use your app (defaults to gmail.com)\n- GOOGLE_AUTH_SCOPE\nthe scope of the authorization (defaults to \"email profile\")\n- GOOGLE_AUTH_REDIRECT_URL\nthe redirect url after google authorization, must change it to some endpoint that contains some business logic of yours (defaults to \"localhost:8000\")\n\nall of them must be set.\n\n### Flow to authenticate\ne.g. (assuming that urls are mounted as in the example above)\n```\n$ curl localhost:8000/auth/code_url\nhttps://accounts.google.com/o/oauth2/v2/auth?client_id=xxxx\u0026redirect_uri=http%3A%2F%2Fwww.127.0.0.1.xip.io%3A8000%2Fauth%2Fcomplete%2F\u0026scope=email+profile\u0026access_type=offline\u0026response_type=code\n```\nUser access the url from a browser and complete the login @ google, GOOGLE_AUTH_REDIRECT_URL will be called, containing the code:\ne.g.\n```\nGOOGLE_AUTH_REDIRECT_URL/?code=xxxxxxxxx#\n```\nCode should then be exchanged by an app token (this will also create a Django User and register google auth and refresh token in the database for further use authenticating every request against google)\n```\ncurl -X POST \"localhost:5000/google_auth/authenticate/?code=xxxxxxxxx\"\n{\"token\": \"xxxxxxxxx-xxxxxxxxxxxxxx-xxxxxxxxxxxxxxx\", \"email\": \"me@felipejfc.com\"}\n```\n\n### Authenticating requests\nAfter completing the above flow, to authenticate an user's request, set an Authorization header\n```\nAuthorization: token xxxxxxxxxx-xxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxx\n```\n\n##### Rest Framework\nFor django rest framework, add google_auth.authentication.GoogleAuthAuthentication to REST_FRAMEWORK.DEFAULT_AUTHENTICATOR_CLASSES\n```\n    'DEFAULT_AUTHENTICATION_CLASSES': (\n        ...\n        google_auth.authentication.GoogleAuthAuthentication,\n    ),\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelipejfc%2Fdjango_google_auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffelipejfc%2Fdjango_google_auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelipejfc%2Fdjango_google_auth/lists"}