问题
I have two web applications on Apache Ubuntu 16.04 Server:
- WordPress 4.8.1 website
- Django 1.11 application (with django-rest-framework)
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 ?
回答1:
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
回答2:
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'
来源:https://stackoverflow.com/questions/45915936/single-sign-on-between-wordpress-and-django