# Gradio Login
OAuth Login for Gradio. Currently supports only Google OAuth.
## Example App
OAuth Popup
![Example 1](/screenshots/0_oauth.png)
Logged in view
![Example 2](/screenshots/1_app.png)
## Installation
```
pip install gradiologin
```
## Getting Started
### Example Code
1. Use below code with your own Google OAuth `client_id` and `client_secret` (if you don't have it, go to [OAuth App Registration](#oauth-app-registration))
```python3
# 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")
```
2. Host locally with `uvicorn app:app`
3. Navigate to `https://localhost:8000`
### OAuth App registration
Go to [Google Developer Console](https://console.cloud.google.com/)
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`, `http://localhost:8000/auth`. In production, change `http://localhost:8000` to your domain name. Save `client_id` and `client_secret`
Raw data
{
"_id": null,
"home_page": null,
"name": "gradiologin",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "gradio, login, oauth, authorization, authentication, auth",
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/34/81/6b7bc192aac73b8e0c8685058e8661b6c2ed2434230fb2506b043dab65eb/gradiologin-0.0.1.tar.gz",
"platform": null,
"description": "# Gradio Login\nOAuth Login for Gradio. Currently supports only Google OAuth.\n\n## Example App\nOAuth Popup\n![Example 1](/screenshots/0_oauth.png)\nLogged in view\n![Example 2](/screenshots/1_app.png)\n\n\n## Installation\n```\npip install gradiologin\n```\n\n## Getting Started\n### Example Code\n1. Use below code with your own Google OAuth `client_id` and `client_secret` (if you don't have it, go to [OAuth App Registration](#oauth-app-registration))\n\n```python3\n# app.py\n\nfrom fastapi import FastAPI\nimport gradio as gr\nimport gradiologin as gl\n\napp = FastAPI()\ngl.register(\n name='google',\n server_metadata_url= 'https://accounts.google.com/.well-known/openid-configuration',\n client_id='YOUR_CLIENT_ID',\n client_secret='YOUR_CLIENT_SECRET',\n client_kwargs={\n 'scope': 'openid email profile',\n },\n)\n\ndef show_user(request: gr.Request):\n user = gl.get_user(request)\n return gr.update(value=user)\n\nwith gr.Blocks() as demo:\n btn_show = gr.Button(\"Get current user\")\n databox = gr.Textbox(interactive=False)\n btn_show.click(show_user, outputs=[databox])\n\n gl.LogoutButton(\"Logout\")\n\ngradio_app = gl.mount_gradio_app(app, demo, \"/app\")\n```\n\n2. Host locally with `uvicorn app:app`\n3. Navigate to `https://localhost:8000`\n\n### OAuth App registration\nGo to [Google Developer Console](https://console.cloud.google.com/)\n1. *New Project > Create*\n2. *APIs & Services > OAuth consent screen > External > Create*. Fill required fields.\n3. *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, change `http://localhost:8000` to your domain name. Save `client_id` and `client_secret`\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "OAuth Login for Gradio",
"version": "0.0.1",
"project_urls": {
"Homepage": "https://github.com/jakjus/gradiologin"
},
"split_keywords": [
"gradio",
" login",
" oauth",
" authorization",
" authentication",
" auth"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a20b3882297985e297ad78b60fb531c913518b59b528c1acd882779b22e48c85",
"md5": "ecbf1e335db0a942a3b86e38870f161f",
"sha256": "85b43687ec5f3052bb2ea11e19e1b833ca7b2830b73c11fc0ca9a5bffef8b824"
},
"downloads": -1,
"filename": "gradiologin-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ecbf1e335db0a942a3b86e38870f161f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 5518,
"upload_time": "2024-04-15T18:51:34",
"upload_time_iso_8601": "2024-04-15T18:51:34.748267Z",
"url": "https://files.pythonhosted.org/packages/a2/0b/3882297985e297ad78b60fb531c913518b59b528c1acd882779b22e48c85/gradiologin-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "34816b7bc192aac73b8e0c8685058e8661b6c2ed2434230fb2506b043dab65eb",
"md5": "385c762a65460808ce243210d92211fd",
"sha256": "ef920157fc4ff867388d3a55eed376a79e504557155fa609af2a0fdffa1215b5"
},
"downloads": -1,
"filename": "gradiologin-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "385c762a65460808ce243210d92211fd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 4137,
"upload_time": "2024-04-15T18:51:36",
"upload_time_iso_8601": "2024-04-15T18:51:36.621870Z",
"url": "https://files.pythonhosted.org/packages/34/81/6b7bc192aac73b8e0c8685058e8661b6c2ed2434230fb2506b043dab65eb/gradiologin-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-15 18:51:36",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jakjus",
"github_project": "gradiologin",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "gradiologin"
}