Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pluggable authentication support #63

Open
paul121 opened this issue Feb 13, 2024 · 0 comments
Open

Pluggable authentication support #63

paul121 opened this issue Feb 13, 2024 · 0 comments
Assignees
Milestone

Comments

@paul121
Copy link
Member

paul121 commented Feb 13, 2024

Let's decouple the authentication mechanism from farmOS.py. Original motivation from #31

Currently we only support the OAuth password credentials flow which has been OK for most use-cases. But going forward we should encourage other OAuth flows (authorization code and client credentials) instead of password. With farmOS v3 and Simple OAuth v6 the password grant is no longer enabled by default. Also, it would be nice to allow API key based auth to support #55

One approach could be to allow a separate auth parameter, as inspiration from both Requests and HTTPX. This is nice and would allow simple auth methods to be reused yet still be customized as needed.

But there have already been a few use-cases for this where we have designed workarounds replacing the farmOS session with a custom session class: eg #55 (comment). This exercise demonstrated how farmOS.py already has much of the logic abstracted to work with any requests compatible session object (and highlighted some things that can be improved).

Thus, the simplest abstraction may be to require that a session is created and prepared (authorized) separately and passed as a required argument when instantiating a farmOS.py client.

This may look like (roughly):

from requests_oauthlib import OAuth2Session
from oauthlib.oauth2 import LegacyApplicationClient
from farmOS import farmOS

# Create an OAuth2Session with password credentials
session = OAuth2Session(
    client=LegacyApplicationClient(client_id='farm'),
    auto_refresh_url=refresh_url,
)

# Authorize via Password Credentials Flow
session.fetch_token(
    token_url=token_url,
    username=username,
    password=password,
    scope='farm_manager',
)

farmos = farmos(url=farm_url, session=session)
@paul121 paul121 added this to the v2 milestone Feb 13, 2024
@paul121 paul121 self-assigned this Feb 13, 2024
@paul121 paul121 mentioned this issue Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant