AnswerDotAI / fasthtml

The fastest way to create an HTML app
https://fastht.ml/
Apache License 2.0
5.22k stars 218 forks source link

[BUG] OAuth URI Errors #483

Open DancingPete opened 4 days ago

DancingPete commented 4 days ago

Bug Description

According to your OAuth documentation, I should be able to call client.login_link() to generate the href for the Oauth redirect handler. However, the sever errors out with the following message:

TypeError: WebApplicationClient.login_link() missing 1 required positional argument: 'redirect_uri'

After much fiddling, I've realized that perhaps the error is the result of the documentation that needs updating. A "more heavily commented example" provides a significantly different workflow which works perfectly.

If I am correct, I would be happy to contribute an updated documentation page. That said, a code update to align the flow with the documentation may be a better approach.

Reproducible Example

# Standard library imports
from os import environ

# Third-party imports
from fasthtml.common import *
from fasthtml.oauth import *

# Constants
GOOGLE_OAUTH_CLIENT_ID = environ.get("GOOGLE_OAUTH_CLIENT_ID")
GOOGLE_OAUTH_CLIENT_SECRET = environ.get("GOOGLE_OAUTH_CLIENT_SECRET")
GOOGLE_OAUTH_REDIRECT = environ.get("GOOGLE_OAUTH_REDIRECT")

# App definition
app, rt = fast_app(debug=environ.get("DEBUG"), live=environ.get("LIVE"))

# Define Google app client
client = GoogleAppClient(
    client_id=GOOGLE_OAUTH_CLIENT_ID,
    client_secret=GOOGLE_OAUTH_CLIENT_SECRET,
    redirect_uri=GOOGLE_OAUTH_REDIRECT)
link = client.login_link()

@rt("/")
def get(): return A(href=link)

@rt("/redirect")
def get(code: str): return P(f"code: {code}")

Note that when creating the client with the from_file(FILE_NAME) class method, everything work swimmingly.

Expected Behaviour

I would expect the client.login_link() to produce the redirect necessary to the oauth flow as described in the documentation walkthrough.

Note that while adding the redirect URI to the method call (i.e. login_link) generates a working link and successfully process the authentication flow, afterwards, the use of retr_id and retr_info both require the redirect URI as positional arguments unlike the the oauth walkthrough documentation, and here, adding the redirect URI fails.

Environment Information

Please provide the following version information:

Confirmation

Please confirm the following:

Additional context

Screenshots

algal commented 3 days ago

I just encountered the same issue with exactly those versions, not only with login_link() but also with .retr_id().