diff --git a/.gitignore b/.gitignore index c9f4f5a45..9fd28c6ce 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ venv .nicegui/ *.sqlite* .DS_Store +.env \ No newline at end of file diff --git a/examples/google-one-tap-auth/main.py b/examples/google-one-tap-auth/main.py new file mode 100755 index 000000000..ee86c60dc --- /dev/null +++ b/examples/google-one-tap-auth/main.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 +import os + +import httpx +from dotenv import load_dotenv +from fastapi import Form, HTTPException, Request +from fastapi.responses import RedirectResponse + +from nicegui import Client, app, core, ui + +# Get your Google Client ID from the Google Cloud Console +# https://developers.google.com/identity/gsi/web/guides/get-google-api-clientid#get_your_google_api_client_id +# and pass it as an environment variable (or write it to an .env file) +load_dotenv() +GOOGLE_CLIENT_ID = os.environ.get('GOOGLE_CLIENT_ID', '') + + +@ui.page('/') +def main_page(request: Request): + assert request.url.hostname + assert core.air + assert core.air.remote_url + if 'on-air.io' not in request.url.hostname: + return RedirectResponse(core.air.remote_url) + + if not GOOGLE_CLIENT_ID: + ui.label('Please set the GOOGLE_CLIENT_ID environment variable') + return + + ui.add_head_html('') + ui.html(f''' +