Single sign-on between WordPress and Django Single sign-on between WordPress and Django wordpress wordpress

Single sign-on between WordPress and Django


I Used this https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/for WP login

I created two insert function for both auth_user(Django) and wp_users(Wordpress)install library

pip install passlib

serializer.py (im using django rest_framework jwt)

from passlib.hash import md5_crypt

from django.contrib.auth.hashers import make_password

registration serializer function (auth_user)

pwd_hash = make_password(password) usrobj = User(username = username, email = email, is_active=True, password = pwd_hash) usrobj.save()

duplicate registration for Wordpress dbtable

wph = md5_crypt.hash(password)wpusrobj = WpUsers(user_login = str(username), user_pass = str(wph), user_nicename='', user_email = str(email), user_url='', user_activation_key='', display_name='', user_status=0)wpusrobj.save()

make sure you run fake migrate your wp tables

this is how you get the table to model

python manage.py inspectdb > models.py

it should look like this: (i just add some null and blank)

class WpUsers(models.Model):    id = models.BigAutoField(db_column='ID', primary_key=True)  # Field name made lowercase.    user_login = models.CharField(max_length=60)    user_pass = models.CharField(max_length=255)    user_nicename = models.CharField(max_length=50, blank=True, null=True)    user_email = models.CharField(max_length=100)    user_url = models.CharField(max_length=100, blank=True, null=True)    user_registered = models.DateTimeField(("Created Date"), default=timezone.now, blank=True, null=True)    user_activation_key = models.CharField(max_length=255, blank=True, null=True)    user_status = models.IntegerField(null=True, blank=True)    display_name = models.CharField(max_length=250, blank=True, null=True)    class Meta:        managed = False        db_table = 'wp_users'


Use below plugin implement JWT token for authentication in wordpress websitehttps://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/

After successful login in wordpress website redirect to Django website, When logout in Django . destroy the session in wordpress viceversa