3rd Party Login in wordpress

Here is some code which i use to login between two site one is in wordpress and one is non-wordpress. I send an ajax request to wordpress site having email and password as data. After get this data on wordpress site i user wp_signon function to login the user. Here is the code.

function sign_in_action() {
    $creds = array();
    $creds['user_login'] = $_REQUEST['username'];
    $creds['user_password'] = $_REQUEST['password'];
    $creds['remember'] = $_REQUEST['remember'];
    $user = wp_signon( $creds, false );
    if ( is_wp_error($user) ):
        echo false;
        exit();
    else:
        echo true;
        exit();
    endif;
}
add_action('wp_ajax_nopriv_sign_in_action', 'sign_in_action');
add_action('wp_ajax_sign_in_action', 'sign_in_action');

Once the login is successful if user come to the wordpress he is login automatically because wordpress save the cookie for the user.

The same code you have to write for logout also if user logout from non-wordpress site you have to logout it from wordpress site. For this you have to send an ajax request to wordpress site which use wp_logout function for logout the user.

function logout_action() {
    wp_logout();
    echo true;
    exit()
}
add_action('wp_ajax_nopriv_logout_action', 'logout_action');
add_action('wp_ajax_logout_action', 'logout_action');

This is working code that i use for my site. I don’t know how you use database of user in wordpress and non-wordpress site. I use common wp_users table for both wordpress and non-wordpress site.