- ๐ญ Iโm currently working at geoimpact AG
khashashin / django-appwrite Goto Github PK
View Code? Open in Web Editor NEWA Django middleware to authenticate users with Appwrite.
License: MIT License
A Django middleware to authenticate users with Appwrite.
License: MIT License
Content:
When using the log_error(e)
function, an incorrect logging format is causing another exception instead of logging the intended error message.
def log_error(e):
import logging
logger = logging.getLogger('django')
logger.error('Error: ', e)
The current logging implementation does not correctly format the error message with the exception e
. This results in a secondary exception being raised during the logging process.
To address this issue, the error logging string should be formatted with a placeholder (%s
) to include the exception message.
def log_error(e):
import logging
logger = logging.getLogger('django')
logger.error('Error: %s', e)
Before starting the process of retrieving the information about user teams, checking if the groups with the same name exist, and assigning users to those groups, it's important to make sure that this task is necessary by checking property in the APPWRITE object in the Django settings.
Cannot resolve keyword 'username' into field. Choices are: date_joined, email, first_name, groups, id, is_active, is_staff, is_superuser, last_login, last_name, logentry, middle_name, password, user_permissions, userprofile
Currently, the logic to retrieve or create a user relies on the filter
method followed by first
. This approach might not be as performant as using the get
method directly, especially since this logic is executed frequently.
Consider using the get
method, which is typically more efficient for retrieving single records, and handle the User.DoesNotExist
exception for cases where the user is not present in the database. This will likely improve the performance of the user retrieval process.
# middleware.py
# Get the Django user by its email
user = User.objects.filter(username=email).first()
# If the user doesn't exist, create it
if not user:
User.objects.create_user(
username=email,
password=password,
email=email)
# authentication.py
# Get or create a corresponding Django user
django_user = User.objects.filter(username=email).first()
if not django_user:
User.objects.create_user(username=email, password=password, email=email)
# middleware.py
try:
# Try to get the Django user by its email
user = User.objects.get(username=email)
except User.DoesNotExist:
# If the user doesn't exist, create it
User.objects.create_user(
username=email,
password=password,
email=email)
# authentication.py
try:
# Try to get the corresponding Django user
django_user = User.objects.get(username=email)
except User.DoesNotExist:
# If the user doesn't exist, create it
User.objects.create_user(username=email, password=password, email=email)
Since we use JWT to authorise the user, we don't need user_id.
After successful authorisation with JWT, we can access the ID from the account itself to generate the password
So I have been checking the code of this plugin.
And it looks like the PROJECT_API_KEY
is not begin used at all.
So you could just provide empty string and it will be still running.
So maybe it's worth to mention in the docs that this particular setting is there only for future
usecases like the groups/memberships check for permission or something?.
Test does not work currently
Reusing the password from an appwrite payload in Django by creating a user can lead to several security problems, including that any admin user in Appwrite will be able to login as any user in Django. This was noticed by @stnguyen90
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.