flet
flet copied to clipboard
Google authentication on desktop doesn't work
Exception: oauthAuthorize command is not supported.
PS C:\Users\Desktop\Projects> & c:/Users/Desktop/Projects/.venv/Scripts/python.exe c:/Users/Desktop/Projects/main.py
Future exception was never retrieved
future: <Future finished exception=Exception('oauthAuthorize command is not supported.')>
Traceback (most recent call last):
File "C:\Program Files\Python312\Lib\concurrent\futures\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\Desktop\Projects\main.py", line 18, in login_click
page.login(provider)
File "C:\Users\Desktop\Projects\.venv\Lib\site-packages\flet_core\page.py", line 565, in login
result = self._send_command("oauthAuthorize", attrs=auth_attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Desktop\Projects\.venv\Lib\site-packages\flet_core\page.py", line 704, in _send_command
return self.__conn.send_command(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Desktop\Projects\.venv\Lib\site-packages\flet_runtime\flet_socket_server.py", line 155, in send_command
result, message = self._process_command(command)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Desktop\Projects\.venv\Lib\site-packages\flet_core\local_connection.py", line 103, in _process_command
return self._process_oauth_authorize_command(command.attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Desktop\Projects\.venv\Lib\site-packages\flet_core\local_connection.py", line 221, in _process_oauth_authorize_command
raise Exception("oauthAuthorize command is not supported.")
Exception: oauthAuthorize command is not supported.
PS C:\Users\Desktop\Projects>
Code : main.py
import flet as ft
from flet.auth.providers import GoogleOAuthProvider
CLIENT_ID = '***********.apps.googleusercontent.com'
CLIENT_SECRET = '*********'
def main(page: ft.Page):
provider = GoogleOAuthProvider(
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
redirect_url="http://localhost:8550/oauth_callback",
)
def login_click(e):
page.login(provider)
data = ft.Column()
def on_login(e):
print("Login error:", e.error)
print("Access token:", page.auth.token.access_token)
print("User ID:", page.auth.user.id)
data.controls.append(
ft.Column([
ft.Text(f"Name:, {page.auth.user["name"]}"),
ft.Text(f"Email:, {page.auth.user["email"]}"),
])
)
page.update()
page.on_login = on_login
page.add(
ft.Column([
ft.Text('Login', size=20),
ft.ElevatedButton("Login", on_click=login_click),
data,
]))
ft.app(target=main)
Description :
I want to create a small data entry desktop app that save data to google sheet using google sheet API. So, in oder the API to work we need authorization flow but when I use google auth in this exemple to get the credentials, the code raises this issue, Please How I can Fix this.
Note : I want this app to work on both Mobile and desktop.
flet version : 0.21.1
Hello, I am having the same problem, even though I have Calendar, the error is thrown by not having "port=8550, view=flet.WEB_BROWSER" in the app(), but if we put that the app on the mobile does not work it remains blank.