Skip to main content

OAuth Login for Gradio

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gradiologin-0.1.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gradiologin-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file gradiologin-0.1.0.tar.gz.

File metadata

  • Download URL: gradiologin-0.1.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for gradiologin-0.1.0.tar.gz
Algorithm Hash digest
SHA256 388fcfb94161fc1a61492fc729bc4dff3e437b8ac063735f5a9e8886b36f35b1
MD5 3a1d0c16cc18490edc95345bdfe99eaa
BLAKE2b-256 7588ca2122597e416e87bbc97201909fcc028f3296b39d6b5b20409d7583d204

See more details on using hashes here.

File details

Details for the file gradiologin-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gradiologin-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for gradiologin-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 111af87a94867f9ca0602976fdbe2f23be8d5557c91b3a4e5c2db096e7f053d0
MD5 bb4e43b1fa666ffc143e0d9fcb8f5741
BLAKE2b-256 fc55c4c397bb0f9a512e9a77daaf49dbdebeaa2487930b23caa62a716ef4bf6e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page