AnswerDotAI / AnswerDotAI/fasthtml

[BUG] OAuth URI Errors

Open
#483 1 comment 0 reactions 1 assignee Claimed by @algal View on GitHub
bug
Dominant language
Jupyter Notebook
Stars
7k
Forks
319
Avg merge
28m
Merged PRs (30d)
3

Description

# Bug Description

According to your [OAuth documentation](https://docs.fastht.ml/explains/oauth.html#a-work-in-progress), 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

```python
# 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.