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

[16.0] [IMP] fastapi: Add endpoint public_url field #438

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from

Conversation

paradoxxxzero
Copy link

This introduces an optional public_url field in order to avoid hardcoding external site url in mails.

(Also used to implement impersonation in fastapi_auth_partner)

@OCA-git-bot
Copy link
Contributor

Hi @lmignon,
some modules you are maintaining are being modified, check this out!

Copy link
Sponsor Contributor

@lmignon lmignon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a little comment but LGTM

fastapi/models/fastapi_endpoint.py Outdated Show resolved Hide resolved
@sbidoul
Copy link
Member

sbidoul commented Sep 19, 2024

@qgroulard

Copy link
Contributor

@qgroulard qgroulard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (code review)

@sbidoul
Copy link
Member

sbidoul commented Sep 20, 2024

I'm not convinced this is the right place to store such a thing.

An API endpoint, by definition, does not have knowledge of all its clients, so this notion of public URL of an endpoint does not really make sense to me.

@sbidoul
Copy link
Member

sbidoul commented Sep 20, 2024

Or maybe I am misunderstanding what this field means? Is it the URL of some public web site using the API (my initial impression, influenced by use cases I know - in which case this does not make sense to me)?

Or is it the URL of the endpoint as exposed via a reverse proxy (in which case I understand, but this may be worth explaining in the help text)?

@paradoxxxzero
Copy link
Author

In our use case a frontend site is based on an unique endpoint.

In this context the public_url field is meant to represent the frontend site url, i.e.: https://oursupersite.shop/

Which is used in mail templating for instance on user registration (on the endpoint /auth/register) : Welcome to oursupersite ! Please click on the link : {public_url} to go to the site.

And for impersonation where the flow goes like this : impersonate button in odoo -redirect-> impersonate endpoint -set cookie on api url + redirect-> public_url.

--

I understand that an api endpoint can be used by several different frontend sites and a frontend site can use several endpoints which in the former case public_url does not make sense.

I also acknowledge that we intentionally mix up the api domain and site domain in impersonation.

--

Thing is, in case of a endpoint <-> site architecture, if we don't store this data on the endpoint, where should it be stored? I'd rather avoir relying on X-Forwarded-Host-like headers and it wouldn't work for the impersonation.

Also for the domain mix up I originally meant to add an api public url field too (the reverse proxy one) but we decided to wait for this need to arise.

@sbidoul
Copy link
Member

sbidoul commented Sep 20, 2024

Yes, there are many scenarios where the backend needs to know some frontend URLs. But I'm not quite sure storing it on the endpoint is the way to go as it means one endpoint=one frontend and that may not be generic enough. Or at least it may not be something we want to "bless" in the base fastapi module.

@paradoxxxzero
Copy link
Author

Fair enough, but the need remains.

Maybe we need a fastapi.frontend model with some context magic for the endpoint to know its current frontend but this seems overkill.

@sbidoul
Copy link
Member

sbidoul commented Sep 20, 2024

Would it make sense for the frontend to communicate itss own URL through the API calls as needed? Or would that have security implications?

@paradoxxxzero
Copy link
Author

Without thinking too much, I'd say yes: imagine forging a registration from a spoofing site, the mail sent to the user would be legit but pointing to the spoofing site. In this case we would need a list of authorized urls which in definitive would be similar to the public_url field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants