Skip to main content

Gradio Login

OAuth Login for Gradio. Supports multiple OAuth Providers with a generic login page.

Installation

pip install gradiologin

Getting Started

Example Code

  1. Use below code with your own OAuth details. You can get client_id and client_secret from your OAuth provider. (e.g. OAuth App Registration)
# app.py

from fastapi import FastAPI
import gradio as gr
import gradiologin as gl

app = FastAPI()

# Google Provider
gl.register(
    name='google',
    icon='google',  # extra argument - refers to a brand icon
    # from Font Awesome (e.g. 'google' --> 'fa-google' icon)
    server_metadata_url='https://accounts.google.com/.well-known/openid-configuration',
    client_id='client_id_here',
    client_secret='client_secret_here',
    client_kwargs={
        'scope': 'openid email profile',
    },
)

# Custom OpenID Provider
gl.register(
    name='custom',
    server_metadata_url='http://localhost:8080/.well-known/openid-configuration',
    client_id='test',
    client_secret='abc',
    client_kwargs={
        'scope': 'openid email profile',
    },
)

def show_user(request: gr.Request):
    user = gl.get_user(request)
    return gr.update(value=user)

with gr.Blocks() as demo:
    btn_show = gr.Button("Get current user")
    databox = gr.Textbox(interactive=False)
    btn_show.click(show_user, outputs=[databox])

    gl.LogoutButton("Logout")

gradio_app = gl.mount_gradio_app(app, demo, "/app")

# add argument: 'no_login_page=True' to gl.mount_gradio_app
# to remove generic '/login' page
  1. Host locally with uvicorn app:app
  2. Navigate to https://localhost:8000

Example App

Log in page Example 1 Logged in view Example 2

OAuth App registration for Google Provider

Go to Google Developer Console

  1. New Project > Create
  2. APIs & Services > OAuth consent screen > External > Create. Fill required fields.
  3. APIs & Services > Credentials > Create Credentials > OAuth Client ID. Application type: Web application. Authorized JavaScript origins: http://localhost:8000 for development. Authorized redirect URIs: http://localhost:8000/login/google, http://localhost:8000/auth/google. In production, change http://localhost:8000 to your domain name. Save client_id and client_secret

Metadata

Release files for gradiologin 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gradiologin 0.1.0
File Size Uploaded
gradiologin-0.1.0.tar.gz 5.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gradiologin 0.1.0
File Interpreter ABI Platform
gradiologin-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.1 kB

Release files / gradiologin-0.1.0.tar.gz

Download URL gradiologin-0.1.0.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
388fcfb94161fc1a61492fc729bc4dff3e437b8ac063735f5a9e8886b36f35b1
BLAKE2b-256 checksum
How to use checksums
7588ca2122597e416e87bbc97201909fcc028f3296b39d6b5b20409d7583d204
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.7

Release files / gradiologin-0.1.0-py3-none-any.whl

Download URL gradiologin-0.1.0-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
111af87a94867f9ca0602976fdbe2f23be8d5557c91b3a4e5c2db096e7f053d0
BLAKE2b-256 checksum
How to use checksums
fc55c4c397bb0f9a512e9a77daaf49dbdebeaa2487930b23caa62a716ef4bf6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page