Flask-User
Flask-User copied to clipboard
Feature request: Support for MongoDB
This feature requires:
- a MongoDbAdapter class with a .save(object) method.
- a TokenManager that accepts string IDs
@sebastiansdrawings has a fork with MongoDB support: See https://github.com/sebastiansdrawings/Flask-User.
Unfortunately, the user sebastiansdrawings is no longer on GitHub. Do you have any tips on writing a DbAdapter for MongoDB?
Hi, maybe you have refused this feature in the past or you are working on this request, but for a my personal project I have made some modify to Flask_User 0.6 and I have made a DBAdapter for support MongoDB (with MongoAlchemy) as backend and now this work.
This feature can ben interesting for the project ? If you are interested can be send my code :)
Best Regards Massimiliano :)
Thanks Massimiliano, If you send me your code, I will try to integrate it into Flask-User at some point (as time permits). You can mail it to: ling DOT thio AT gmail DOT com. Thanks! Ling
On Tue, Mar 14, 2017 at 1:45 AM, Massimiliano Dal Cero < [email protected]> wrote:
Hi, maybe you have refused this feature in the past or you are working on this request, but for a my personal project I have made some modify to Flask_User 0.6 and I have made a DBAdapter for support MongoDB (with MongoAlchemy) as backend and now this work.
This feature can ben interesting for the project ? If you are interested can be send my code :)
Best Regards Massimiliano :)
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/lingthio/Flask-User/issues/37#issuecomment-286356882, or mute the thread https://github.com/notifications/unsubscribe-auth/AEacJG9zGaxiZ6pr6WJARg3a27CK2tZVks5rllPCgaJpZM4CuHjY .
I send to you a .zip file with the only files that I touched :) (Note: MongoAlchemyAdapter is in init_app.py )
in the code, you can find "#YATTA" for a fast check of code that I modifed ;)
Because I read today that mongoalchemy is no longer supported (https://github.com/jeffjenkins/MongoAlchemy) I migrated to mongoengine that is alive :)
I also need a Flask-user with mongo. When feature will be implemented? Thank you!
I looked at yattamax's zip file and I can not accept this contribution. There are too many places where one of the following is used:
- if hasattr(self.db_adapter, 'id_as_str') and self.db_adapter.id_as_str
- if db_adapter.class.name == "MongoAlchemyAdapter"
This defeats the purpose of making the code agnostic to the underlying DB (and in this case to the underlying DbAdapter).
The approach I'd like to see:
-
Add a db_adapter.save_object() method that saves an object in MongoAdapter, and does nothing in SQLAlchemyAdapter. Add calls to db_adapter.save_object() in the FlaskUser code without a test.
-
Change FlaskUser so that record IDs are always treated as a string (this will be a lot of work). Then, in SQLAlchemyAdapter, convert string IDs to integer IDs.
See #166
OK. Good news and Bad news:
Good news: Using your example code for MongoAlchemy, I managed to get a MongoAlchemyDbAdapter up and running for most functionalities. Mongo ObjectIDs can be retrieved as a hex string, which can be converted to a Python Integer. There were a lot of places where Flask-User just changes an object attribute, which needed to be replaced with a call to db_adapter.update_object(): user.confirmed_at=now() --> db_adapter.update_object(user, confirmed=now()).
Bad news: These object Id integers have more than 16 digits, which the current token manager can not handle (it assumed integers were less than 16 digits). In v0.9 of Flask-User I was able to make the token manager handle unlimited length integers, but this breaks backward compatibility for v0.6.
Another issue that needs to be resolved is that Flask-User currently relies on User.roles for role-based authentication, implemented as a UserRoles pivot table. This needs to be reworked so that we can use a ListField in MongoAlchemy.
I will continue to work on this in the v0.9 branch of the code, and will update this issue if progress is made.
Ling
Flask-User v0.9 (alpha) and v1.0 (stable) will have MongoDB support via Flask-MongoEngine. The TokenManager has been rewritten to allow (a list of) integers and strings. I'm not sure when I will be releasing v0.9.
As far as I can see current version of Flask-User supports Mongo. Can we close this issue? Is it still relevant?