I have two web applications on Apache Ubuntu 16.04 Server:
I want to install a Single Sign-On service (SSO). For instance, User logs on WordPress, then when he goes to Django website, he is already connected. Actually I don't find anything about SSO between WordPress and Django. Do you have an idea how to do it ?
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
pwd_hash = make_password(password)
usrobj = User(username = username, email = email, is_active=True, password = pwd_hash)
usrobj.save()
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()
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 website https://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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With