Metadata-Version: 2.4
Name: django_gauth
Version: 0.3.1
Summary: A Django app for providing the Google's discovery based Oauth2 authentication mechanism is HTTP/HTTPS oriented Django Servers/Projects.
Author-email: Ankit Kumar <ankit.kumar05@telusdigital.com>, Ankit Yadav <ankit8290@gmail.com>
Maintainer-email: Ankit yadav <ankit8290@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Ankit Yadav
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Documentation, https://masterpiece93.github.io/django-gauth/
Project-URL: Source, https://github.com/masterPiece93/django-gauth
Project-URL: Issues, https://github.com/masterPiece93/django-gauth/issues
Project-URL: Changelog, https://github.com/masterPiece93/django-gauth/blob/main/CHANGELOG.md
Keywords: django_gauth,google,oauth2,auth
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 3.1
Classifier: Framework :: Django :: 3.2
Classifier: Framework :: Django :: 4.0
Classifier: Framework :: Django :: 4.1
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.0
Classifier: Framework :: Django :: 5.1
Classifier: Framework :: Django :: 5.2
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Internet :: WWW/HTTP :: Session
Classifier: Topic :: Security
Classifier: Topic :: Utilities
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: google-auth-oauthlib<1.3.0,>=1.0.0
Requires-Dist: Django>=3.1; python_version >= "3.9" and python_version < "3.11"
Requires-Dist: Django>=4.2.26; python_version >= "3.9"
Dynamic: license-file

# Google Auth <sup>[ Django ]</sup>

[![PyPI version](https://img.shields.io/pypi/v/django-gauth?label=PyPI&color=blue)](https://pypi.org/project/django-gauth/)
[![Python versions](https://img.shields.io/pypi/pyversions/django-gauth)](https://pypi.org/project/django-gauth/)
[![Django versions](https://img.shields.io/pypi/frameworkversions/django/django-gauth?label=Django&color=0C4B33)](https://pypi.org/project/django-gauth/)
[![Downloads](https://img.shields.io/pypi/dm/django-gauth?label=downloads&color=brightgreen)](https://pypi.org/project/django-gauth/)
[![License](https://img.shields.io/pypi/l/django-gauth?color=green)](https://github.com/masterPiece93/django-gauth/blob/main/LICENSE)
[![Documentation](https://img.shields.io/badge/docs-online-blue)](https://masterpiece93.github.io/django-gauth/)
[![tests](https://github.com/masterPiece93/django-gauth/actions/workflows/tests.yml/badge.svg)](https://github.com/masterPiece93/django-gauth/actions/workflows/tests.yml)
[![coverage](https://raw.githubusercontent.com/masterPiece93/django-gauth/badges/coverage.svg)](https://github.com/masterPiece93/django-gauth/actions/workflows/tests.yml)
[![pages-build-deployment](https://github.com/masterPiece93/django-gauth/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/masterPiece93/django-gauth/actions/workflows/pages/pages-build-deployment)
[![Pylint](https://github.com/masterPiece93/django-gauth/actions/workflows/pylint.yml/badge.svg)](https://github.com/masterPiece93/django-gauth/actions/workflows/pylint.yml)

> [Official Documentation](https://masterpiece93.github.io/django-gauth/)
> [Demo Integration / Samples](https://github.com/masterPiece93/django_gauth_samples)

## Why django-gauth?

> **Google sign-in for Django in 5 minutes — without the django-allauth configuration maze.**

`django-gauth` does exactly one thing well: add **Google OAuth2 login** to an HTTP/HTTPS Django
project, with a working landing page included — no multi-provider abstractions, no sprawling
configuration, just the Google flow, clearly documented.

| | **django-gauth** | **django-allauth** | **Roll-your-own** |
| --- | :---: | :---: | :---: |
| Setup for *just Google* | ⚡ Minimal (3 settings + 1 URL include) | 🧩 Broad, multi-step config | 🛠️ Manual OAuth wiring |
| Built-in login page | ✅ Ships a landing page | ➖ Bring your own templates | ❌ Build it yourself |
| Nested & dynamic auth (return-to-origin) | ✅ Built-in schemes | ➖ DIY | ❌ DIY |
| Session lifecycle (auto-refresh + revoking logout) | ✅ Built-in, configurable policy | ➖ DIY | ❌ DIY |
| Scope | 🎯 Google OAuth2 only | 🌐 Many providers | 🎯 Whatever you build |
| Needs a `User` model + migrations | ✅ No — session-only | ➖ Yes — DB-backed | 🛠️ Up to you |
| Learning curve | 📉 Low | 📈 Higher (large surface) | ⚠️ Easy to get OAuth subtly wrong |
| Typed & tested | ✅ Type hints + 100% coverage | ✅ Mature | ➖ Up to you |

**Reach for `django-allauth` or `python-social-auth`** when you need real user *accounts* — a
`User` row per person, many providers, account linking, or email workflows. **Reach for
`django-gauth`** when you just need to answer *"is this a signed-in Google user?"* for an **SPA or
API backend** — session-only, **no `User` model, no migrations** — with a JSON `/gauth/session`
probe and a configurable session policy.

> ℹ️ Transparent refresh and SPA support aren't unique (social-auth has a refresh helper; allauth
> has a Headless API). `django-gauth`'s contribution is delivering them in that **stateless,
> `User`-model-free** setting — where you'd otherwise wire it by hand.

## ✨ Standout feature — Nested & Dynamic Auth

Modern UIs place the *"Sign in with Google"* button **inline** — inside modals, deep within a
workflow, or when a session expires mid-task. `django-gauth` brings users **back to the exact
page (and state) they authenticated from**, out of the box — no more dumping them on a generic
dashboard.

- 🎯 **Return-to-origin redirection** — send users straight back to where they started.
- 🧩 **SPA-ready** — first-class support for React/Vue via query-parameter *or* header schemes
  (`PRESERVE_ORIGIN_QP` / `PRESERVE_ORIGIN_HP`), with `redirect` or `json` responses.
- 🔒 **Safe by default** — origins are same-origin validated to block open-redirect attacks.

> 📌 **Availability:** This feature is available in `django-gauth >= 0.3.0`.

👉 **[Read about Redirection Schemes →](https://masterpiece93.github.io/django-gauth/concepts/redirection-schemes/)**

## ✨ Standout feature — Django User Integration *(opt-in)*

Want `request.user`, `@login_required`, and **admin** login backed by Google — *without* an
extra `User` model, a token table, or migrations? Flip one switch and `django-gauth` maps
Google identities onto your project's **existing** `AUTH_USER_MODEL`:

- 👤 **Real `request.user`** — `@login_required`, `LoginRequiredMixin`, and the Django admin just work.
- 🧩 **Zero `django-gauth` migrations** — get-or-create on your existing `auth_user`; no models of our own.
- 🛡️ **Safe by default** — verified-email gated, unusable passwords, and a `manage.py check` for misconfig.
- 🔌 **Dual-mode guards** — `gauth_required` / `GauthRequiredMixin` work with *or* without integration.

> 📌 **Availability:** This feature is available in `django-gauth >= 0.3.0`.

> ⚠️ **Limitation:** The view-protection guards (`gauth_required` / `GauthRequiredMixin`)
> support **Django native views only** — they are **not** compatible with
> [Django REST Framework](https://www.django-rest-framework.org/) views (`APIView`,
> `ViewSet`, `@api_view`). DRF-native adapters are planned; until then, protect DRF
> endpoints with DRF's own authentication/permission classes. See the
> [troubleshooting notes](https://masterpiece93.github.io/django-gauth/guides/troubleshooting/#known-limitations).

👉 **[Read about Django User Integration →](https://masterpiece93.github.io/django-gauth/concepts/django-user-integration/)**

## Installation

<!-- Implement Carousal -->

| Source | Command |
| ------ | ------- |
| **GitHub** | ```pip install -e git+https://github.com/masterPiece93/django-gauth.git#egg=django_gauth```|
| **PyPi**| ```pip install django-gauth``` |

> 📌 **Compatibility note:** If you must stay on `django-gauth < 0.2.1`, pin
> `google-auth-oauthlib<1.3.0,>=1.0.0` in your project requirements to avoid
> PKCE-related OAuth failures. Higher Versions `0.2.1+` pin this for you, so no need to worry with them!

## Quickstart

1. add the app name : `django_gauth` in **INSTALLED_APPS** entry of you project ( in settings.py file )
2. add required configuration variables ( in *settings.py* file )    
    ```python
    # settings.py
    GOOGLE_CLIENT_ID= env("GOOGLE_CLIENT_ID")           # << set according to your oauth2 client
    GOOGLE_CLIENT_SECRET= env("GOOGLE_CLIENT_SECRET")   # << set according to your oauth2 client
    GOOGLE_AUTH_FINAL_REDIRECT_URL= None        # defaults to `<host>/gauth/`
    CREDENTIALS_SESSION_KEY_NAME= "credentials" # defaults to `credentials`
    STATE_KEY_NAME= "oauth_state"               # defaults to `oauth_state`
    SCOPE= [
        "https://www.googleapis.com/auth/userinfo.email"    # always preffered
        ,"https://www.googleapis.com/auth/userinfo.profile" # always preffered
        ,"openid"                                           # always preffered
        ,"https://www.googleapis.com/auth/drive"            # based on your usage
    ]
    os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'         # strictly for local-development only
    ```

    - `os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'` directs the server to accept in-secure (http) connections .

3. configure auth urls ( in *urls.py* file of root )
    ```python
    # urls.py
    from django.contrib import admin
    from django.urls import path, include

    urlpatterns = [
        path('admin/', admin.site.urls),
        path('gauth/', include('django_gauth.urls')),
        
        # add your other app's urls
        # ...

    ]
    ```
4. now run your project server
    - once your server is up & running , navigate to `.../gauth`, this is the master interface ( default landing page )
    - click on `Authenticate` button to launch Google Oauth2 Login .
    - just follow the flow you are directed to .
    - post authentication , you'll be redirected back to `.../gauth`

* NOTE : 
    useually all servers ( **wsgi**, **asgi**, **uWsgi**) runs default on `http://127.0.0.1:PORT/` , hence always take care to set the redirect endpoints in your google oauth2 client app in accordance with *127.0.0.1* , don't mistake to consider *localhost* , *0.0.0.0* and *127.0.0.1* as the same thing while dealing with redirect uri's . 
    - For example : suppose you have set `http://localhost:PORT/gauth/google-callback` as your redirect uri , then take note of running your django app on localhost:PORT only !!

---

## Changelog

See [`CHANGELOG.md`](https://github.com/masterPiece93/django-gauth/blob/main/CHANGELOG.md) for the full release history and notable changes in each version.

<br>

## Releases

See [`Github Releases`](https://github.com/masterPiece93/django-gauth/releases) for the details of each release in each version .

<br>

