Auteur Sujet: WordPress Login and Signing In To MushRaider At Same Time  (Lu 7474 fois)

websitecenter

  • Newbie
  • *
  • Messages: 3
    • Voir le profil
I read the Single Sign On article here: http://mushraider.com/en/documentation/bridge-doc/

I have tried the single sign on with the code similar to below by adding an add_action to my WordPress theme's functions.php file.

What I want to do is that when a user logs into my WordPress site, they are also logged into the MushRaider installation which is located in a directory in the root folder of our WordPress installation.

It's still not working. Is the JSON data I am passing through not acceptable or is the URL I'm sending to wrong.

<?php
add_action('wp_login', 'loginMushRaider', 10, 2);

function loginMushRaider($user_login, $user) {
$url = 'http://mywebsite.com/mushraider/auth/login';
$data = array();
$data['User']['username'] = 'myuser';
$data['User']['password'] = '12345';
$data['User']['email'] = 'myuser@email.com';

$content = json_encode($data);
 
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //curl error SSL certificate problem, verify that the CA cert is OK
 
$result     = curl_exec($curl);
$response   = json_decode($result);
var_dump($response);
curl_close($curl);
}
?>

Mush

  • Mushraider
  • Administrator
  • Hero Member
  • *****
  • Messages: 768
  • Meh.
    • Voir le profil
    • MushRaider
Re : WordPress Login and Signing In To MushRaider At Same Time
« Réponse #1 le: 14 août 2015, 09:05:39 »
I already developed a plugin for MushRaider https://wordpress.org/plugins/mushraider-bridge/
The MushRaider API let users use their credential of another website, but they will not be logged in automatically.

What this do :
For exemple, to login into MushRaider I will be able (and forced) to use my Wordpress's credentials, but I will have to type them at least once (until the session / cookies expires).

What this don't :
When I login into Wordpress, I will not be automacally logged to MushRaider

To change that, you will have to generate the MushRaider cookie (used by "remember me") when logging in to Wordpress
MushRaider - modern raid planner for modern raiders
Me suivre sur  twitter and Google+
Soutenir le projet et me payer une bière =)

websitecenter

  • Newbie
  • *
  • Messages: 3
    • Voir le profil
Re : WordPress Login and Signing In To MushRaider At Same Time
« Réponse #2 le: 14 août 2015, 20:14:37 »
I made an add_action function right after the WordPress login, but am not sure on which cookies exactly to set (the name of the cookies and the values in the cookies).

I looked in the Controller file, AuthController.php in the goLogin() function which shows that the username and password is being stored.

However, it is still not working and we need the solution for storing MushRaider cookies right after someone logs into WordPress.

Here is the code I have in the WordPress theme's functions.php file:

<?php
add_action
('wp_login''setMushRaiderCookie'102);

function 
setMushRaiderCookie($user_login$user) {

$userValues = array(
'username' => $user->user_login,
'password' => $user->user_pass
);
$userValues json_encode($userValues);

  
setcookie'CakeCookie[User]'$userValuestime()+60*60*24*30nullnullfalsetrue );
  
setcookie'CAKEPHP''cc07522b99aa5c254e4cf945ad7dbf2c'time()+60*60*24*30nullnullfalsetrue  );
  
}
?>

« Modifié: 14 août 2015, 20:52:44 par websitecenter »

websitecenter

  • Newbie
  • *
  • Messages: 3
    • Voir le profil
Re : Re : WordPress Login and Signing In To MushRaider At Same Time
« Réponse #3 le: 27 août 2015, 23:06:15 »
To change that, you will have to generate the MushRaider cookie (used by "remember me") when logging in to Wordpress

What is the exact cookie name and value that we must generate and store on our site.