OAuth Login for Gradio
Project description
Gradio Login
OAuth Login for Gradio. Currently supports only Google OAuth.
Example App
OAuth Popup Logged in view
Installation
pip install gradiologin
Getting Started
Example Code
- Use below code with your own Google OAuth
client_id
andclient_secret
(if you don't have it, go to OAuth App Registration)
# app.py
from fastapi import FastAPI
import gradio as gr
import gradiologin as gl
app = FastAPI()
gl.register(
name='google',
server_metadata_url= 'https://accounts.google.com/.well-known/openid-configuration',
client_id='YOUR_CLIENT_ID',
client_secret='YOUR_CLIENT_SECRET',
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")
- Host locally with
uvicorn app:app
- Navigate to
https://localhost:8000
OAuth App registration
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:8000
for development. Authorized redirect URIs:http://localhost:8000/login
,http://localhost:8000/auth
. In production, changehttp://localhost:8000
to your domain name. Saveclient_id
andclient_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.0.1.tar.gz
(4.1 kB
view hashes)
Built Distribution
Close
Hashes for gradiologin-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85b43687ec5f3052bb2ea11e19e1b833ca7b2830b73c11fc0ca9a5bffef8b824 |
|
MD5 | ecbf1e335db0a942a3b86e38870f161f |
|
BLAKE2b-256 | a20b3882297985e297ad78b60fb531c913518b59b528c1acd882779b22e48c85 |