s3rius / FastAPI-template

Feature rich robust FastAPI template.
MIT License
1.94k stars 171 forks source link

feat: Add fastapi-users support #143

Closed andcarnivorous closed 1 year ago

andcarnivorous commented 1 year ago

Adds support to fastapi-users by adding the option to the menu and creating views for JWT, cookie and OAuth authentication. Adds user models and views. This is only compatible with SQLAlchemy.

Tested locally and users can be registered and log in works.

register2 login user

s3rius commented 1 year ago

Hi and thanks for your work! Instead of writing in docs that it works only with SQLAlchemy, please define is_hidden property.

Like this:

is_hidden=check_orm(['sqlalchemy'])

After you do this, this entry will only show up if the chosen orm is SQLAlchemy.

s3rius commented 1 year ago

As I see, you added all possible backends and it's really great. But the problem is that every time people choose an option to add users, they need to delete many lines. I suggest you a solution. You can add new menu if users are enabled.

This would be a multiselect menu with options like:

I can help implementing it. Or you can do it yourself.

andcarnivorous commented 1 year ago

I can help implementing it. Or you can do it yourself.

@s3rius I can work on it no problem. I'll address the other points as well. Do you prefer single atomic commits on PR's?

s3rius commented 1 year ago

Hi, @andcarnivorous, you can do as you want. I'll sqash commits when it's merged.

andcarnivorous commented 1 year ago

I have removed the google oauth stuff for now. Maybe I'll open another PR for that in the future just for it

s3rius commented 1 year ago

@andcarnivorous, thank you. Please tell me when the PR is ready for another review.

BTruer commented 1 year ago

any updates with this?

andcarnivorous commented 1 year ago

any updates with this?

Hey, really sorry, it's been a year busier than expected and completely forgot about this PR, I'll try to update it and finalize it in the following days! Sorry for forgetting about this

andcarnivorous commented 1 year ago

I have opted for skipping the users module from mypy checks, the others seem to be mypy compliant and everything is fine with flake8. The reason for skipping the mypy checks in the users.py module is that fastapi-users provides classes that inherit from Generics and it seems to be a pain to manage to make them mypy compliant so far (never found myself having to deal with this type of thing, so if anyone knows how to approach this the right way please do).

BTruer commented 1 year ago

How can I test this out?

  1. clone the repo
  2. git checkout andcarnivorous:master
  3. something something to execute fastapi_template
  4. enable users option during interactive setup

otherwise LGTM

@s3rius @andcarnivorous

andcarnivorous commented 1 year ago

How can I test this out?

1. clone the repo

2. git checkout andcarnivorous:master

3. something something to execute fastapi_template

4. enable `users` option during interactive setup

otherwise LGTM

You have to:

  1. Clone my fork ( git clone https://github.com/andcarnivorous/FastAPI-template)
  2. Create a virtual environment for the project
  3. install dependencies and cli with python -m pip install . in the root of the repo.
  4. Run the cli with python3 -m fastapi_template
  5. Give the project name and choose:
    1. REST API
    2. SQLITE/Postgres database
    3. SQLAlchemy as ORM
    4. Add fastapi-users support in the additional tweaks section.
s3rius commented 1 year ago

@andcarnivorous, I truly grateful for your work. You've put so much effort into this. It's really hard to extend such templators.

Thank you very very much.

andcarnivorous commented 1 year ago

@andcarnivorous, I truly grateful for your work. You've put so much effort into this. It's really hard to extend such templators.

Thank you very very much.

No problem! It was fun and glad it could contribute.