2016-11-25 65 views
0

我有一个网站,我必须对在另一个系统(本例中为Kayako支持系统)中注册的用户进行身份验证。 我想我必须使用这些API来解决这个问题,但我并不知道如何开始。将API身份验证集成到WordPress

有人可以帮我解决这个问题吗?我如何发送验证所需的数据,以及如何管理我从Kayako获得的响应。

回答

1

找出Kayako系统的API是怎样的。在WordPress中,你可以做类似这样的事情,以便对用户进行验证:

// this action is executed just before the invocation of the WordPress authentication process 
add_action('wp_authenticate','checkTheUserAuthentication'); 

function checkTheUserAuthentication() { 

    $username=$_POST['log']; 
    $password=$_POST['pwd']; 

    // try to log into the external service or database with username and password 
    $ext_auth = try2AuthenticateExternalService($username,$password); 

    // if external authentication was successful 
    if($ext_auth) { 

     // find a way to get the user id 
     $user_id = username_exists($username); 
     // userdata will contain all information about the user 
     $userdata = get_userdata($user_id); 
     $user = set_current_user($user_id,$username); 

     // this will actually make the user authenticated as soon as the cookie is in the browser 
     wp_set_auth_cookie($user_id); 
     // the wp_login action is used by a lot of plugins, just decide if you need it 
     do_action('wp_login',$userdata->ID); 

     // you can redirect the authenticated user to the "logged-in-page", define('MY_PROFILE_PAGE',1); f.e. first 
     header("Location:".get_page_link(MY_PROFILE_PAGE)); 
    } 

} 

try2AuthenticateExternalService()方法应该包含一些卷曲请求(或类似)的远程服务。

+0

你能举个例子吗? – StoneSmith