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
- Use below code with your own OAuth details. You can get
client_idandclient_secretfrom 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
- Host locally with
uvicorn app:app - Navigate to
https://localhost:8000
Example App
Log in page
Logged in view
OAuth App registration for Google Provider
Go to Google Developer Console
- New Project > Create
- APIs & Services > OAuth consent screen > External > Create. Fill required fields.
- APIs & Services > Credentials > Create Credentials > OAuth Client ID. Application type: Web application. Authorized JavaScript origins:
http://localhost:8000for development. Authorized redirect URIs:http://localhost:8000/login/google,http://localhost:8000/auth/google. In production, changehttp://localhost:8000to your domain name. Saveclient_idandclient_secret
Project details
Release history Release notifications | RSS feed
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)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
388fcfb94161fc1a61492fc729bc4dff3e437b8ac063735f5a9e8886b36f35b1
|
|
| MD5 |
3a1d0c16cc18490edc95345bdfe99eaa
|
|
| BLAKE2b-256 |
7588ca2122597e416e87bbc97201909fcc028f3296b39d6b5b20409d7583d204
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
111af87a94867f9ca0602976fdbe2f23be8d5557c91b3a4e5c2db096e7f053d0
|
|
| MD5 |
bb4e43b1fa666ffc143e0d9fcb8f5741
|
|
| BLAKE2b-256 |
fc55c4c397bb0f9a512e9a77daaf49dbdebeaa2487930b23caa62a716ef4bf6e
|