fasthtml icon indicating copy to clipboard operation
fasthtml copied to clipboard

[BUG] OAuth URI Errors

Open DancingPete opened this issue 4 months ago • 1 comments

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:

  • fastlite version: 0.0.11
  • fastcore version: 1.7.10
  • fasthtml version: 0.6.9

Confirmation

Please confirm the following:

  • [x] I have read the FAQ (https://docs.fastht.ml/explains/faq.html)
  • [x] I have provided a minimal reproducible example
  • [x] I have included the versions of fastlite, fastcore, and fasthtml
  • [x] I understand that this is a volunteer open source project with no commercial support.

Additional context

Screenshots

DancingPete avatar Sep 30 '24 04:09 DancingPete