0
我有一個網站,我必須對在另一個系統(本例中爲Kayako支持系統)中註冊的用戶進行身份驗證。 我想我必須使用這些API來解決這個問題,但我並不知道如何開始。將API身份驗證集成到WordPress
有人可以幫我解決這個問題嗎?我如何發送驗證所需的數據,以及如何管理我從Kayako獲得的響應。
我有一個網站,我必須對在另一個系統(本例中爲Kayako支持系統)中註冊的用戶進行身份驗證。 我想我必須使用這些API來解決這個問題,但我並不知道如何開始。將API身份驗證集成到WordPress
有人可以幫我解決這個問題嗎?我如何發送驗證所需的數據,以及如何管理我從Kayako獲得的響應。
找出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()
方法應該包含一些捲曲請求(或類似)的遠程服務。
你能舉個例子嗎? – StoneSmith