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

FastAPI: Ensure the 'interactive' key is properly set in all _check_credentials environments #444

Open
denaux opened this issue Aug 13, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@denaux
Copy link

denaux commented Aug 13, 2024

Module

Odoo FastAPI (technical name: fastapi)

Describe the bug

A WARNING is logged when sending a request to any endpoint operation that bases its authentication method on authenticated_partner_from_basic_auth_user (after the user provides correct credentials).

WARNING [database_name] odoo.addons.base.models.res_users: _check_credentials without 'interactive' env key, assuming interactive login. Check calls and overrides to ensure the 'interactive' key is properly set in all _check_credentials environments

To Reproduce

Affected versions: v15, v16, v17.

Steps to reproduce the behavior:

  1. Make sure to install the module fastapi with demo data.
  2. In Odoo, open the FastAPI app.
  3. In the tree view, at the end of the entry corresponding to 'Fastapi Demo Endpoint', click the big "Sync Registry" button (or open the record and click the smart button at the top of that Form view).
  4. In your browser, access the demo endpoint '/fastapi_demo/demo/who_ami'.
  5. If a 'Sign In' pop-up appears, fill in a Username and Password of a known user of your database.

Expected behavior
A sole log message INFO [database_name] odoo.addons.base.models.res_users: Login successful for db:[database_name] login:[your_filled_in_username] from [IP]

But now, a WARNING as described above precedes this log message.

Additional context
This WARNING is logged whenever a request is sent to an API endpoint that depends on the provided standard method basic_auth_user, after the user provides correct credentials.

def basic_auth_user(
    credential: Annotated[HTTPBasicCredentials, Depends(HTTPBasic())],
    env: Annotated[Environment, Depends(odoo_env)],
) -> Users:
    username = credential.username
    password = credential.password
    try:
        uid = (
            env["res.users"]
            .sudo()
            .authenticate(
                db=env.cr.dbname, login=username, password=password, user_agent_env=None
            )
        )
        return env["res.users"].browse(uid)
    ...

The issue is resolved if the keyword argument user_agent_env=None is replaced by a dict with some (bool) value assigned to the key "interactive", for example user_agent_env={"interactive": False}.

@denaux denaux added the bug Something isn't working label Aug 13, 2024
@denaux denaux changed the title fastapi: Ensure the 'interactive' key is properly set in all _check_credentials environments. FastAPI: Ensure the 'interactive' key is properly set in all _check_credentials environments. Aug 13, 2024
@denaux denaux changed the title FastAPI: Ensure the 'interactive' key is properly set in all _check_credentials environments. FastAPI: Ensure the 'interactive' key is properly set in all _check_credentials environments Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant