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
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)
| File | Size | Uploaded | |
|---|---|---|---|
| gradiologin-0.1.0.tar.gz | 5.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|