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

feat: Add fastapi-users support #143

Merged
merged 5 commits into from
Sep 12, 2023
Merged

Conversation

andcarnivorous
Copy link
Contributor

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
Copy link
Owner

s3rius commented Jan 14, 2023

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
Copy link
Owner

s3rius commented Jan 14, 2023

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:

  • oauth2 support;
  • cookie auth backend
  • bearer auth backend

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

@andcarnivorous
Copy link
Contributor Author

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
Copy link
Owner

s3rius commented Jan 15, 2023

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

@andcarnivorous
Copy link
Contributor Author

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

@s3rius
Copy link
Owner

s3rius commented Jan 21, 2023

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

@BTruer
Copy link

BTruer commented Aug 8, 2023

any updates with this?

@andcarnivorous
Copy link
Contributor Author

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

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.
Fastapi-users option depends on sqlalchemy, add multimenu for users
backend type. Removes oauth with google for now. Removes unnecessary
methods.
The users module is skipped from type checking since fastapi-users
uses a series of classes that inherit from Generics which makes type
hinting compliance with MyPy painful to work with.
@andcarnivorous
Copy link
Contributor Author

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

Copy link

@BTruer BTruer left a comment

Choose a reason for hiding this comment

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

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

@BTruer
Copy link

BTruer commented Sep 8, 2023

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
Copy link
Contributor Author

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.

Copy link
Owner

@s3rius s3rius left a comment

Choose a reason for hiding this comment

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

The PR looks good.

@s3rius s3rius changed the base branch from master to develop September 12, 2023 08:17
@s3rius s3rius merged commit 656eb7b into s3rius:develop Sep 12, 2023
2 checks passed
@s3rius
Copy link
Owner

s3rius commented Sep 12, 2023

@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
Copy link
Contributor Author

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

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

Successfully merging this pull request may close these issues.

None yet

3 participants