AnswerDotAI / AnswerDotAI/fasthtml

[BUG] OAuth Class calls login_link with parameter signature that does not match provided clients

Open
#675 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Jupyter Notebook
Stars
7k
Forks
319
Avg merge
28m
Merged PRs (30d)
3

Description

I get this error when implementing auth from the docs:

```
TypeError: Auth0AppClient.login_link() got an unexpected keyword argument 'scope'
```

In the docs, the OAuth class is used to add auth to an app like this:

```python
class Auth(OAuth):
def get_auth(self, info, ident, session, state):
email = info.email or ''
if info.email_verified and email.split('@')[-1]=='answer.ai':
return RedirectResponse('/', status_code=303)

app = FastHTML()
oauth = Auth(app, client)
```

This then is supposed to provide the login url to link to the client login through `oauth.login_link(req)`. However, in the OAuth class, the client login link is called like this:
```python
def login_link(self, req, scope=None, state=None): return self.cli.login_link(self.redir_url(req), scope=scope, state=state)
```

This passes the parameters to the `login_link()` method of many clients that don't exist, for example:

DiscordAppClient:
```python
def login_link(self):
```

Auth0AppClient
```python
def login_link(self, req):
```

**Minimal Reproducible Example**

```python
import os

import fasthtml.common as fh
from dotenv import load_dotenv
from fasthtml.oauth import Auth0AppClient, OAuth

_ = load_dotenv()

class Auth(OAuth):
def get_auth(self, info, ident, session, state):
return fh.RedirectResponse("/", status_code=303)

client = Auth0AppClient(
os.getenv("AUTH0_DOMAIN"),
os.getenv("AUTH0_CLIENT_ID"),
os.getenv("AUTH0_CLIENT_SECRET"),
)

app = fh.FastHTML()
oauth = Auth(app, client)

@app.get("/")
def home(auth):
return fh.P("Logged in!"), fh.A("Log out", href="/logout")

@app.get("/login")
def login(req):
return fh.Div(fh.P("Not logged in"), fh.A("Log in", href=oauth.login_link(req)))
```

**Expected behavior**
I would expect the app to launch with a "Not logged in" link to the client login page.

**Environment Information**
Please provide the following version information:
- fastlite version: 0.1.2
- fastcore version: 1.7.29
- fasthtml version: 0.12.4

**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.

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.