如何为第三方登录服务创建登录表格

问题描述 投票:1回答:1

我有上学的任务。我需要制作Wordpress登录表单插件

我被困在这部分:

“在登录时,您应该将数据发送到第三方登录服务,这将在服务器端发生。

*登录应该通过使用WP API功能在服务器端完成。

*这是需要使用CURL调用的外部API服务,以下是示例URL:

Request URL: http://example.com/wp-json/example/login/? Request Method: POST Content-Type: application/json; charset=UTF-8 Post body object: { "username": "usernameinput", "password": "passwordinput" }"

我写了一些代码:

test_plugin.php

<form action="wp-admin/admin-post.php" method="post">
  <input type="hidden" name="action" value="test_login">

add_action( 'admin_post_test_login', 'identify_user' );

function identify_user() {

        $response = wp_remote_post( 'http://wordpress.test/wp-admin/', array(
                'method' => 'POST',
                'headers' => array('Content-Type' => 'application/json; charset=utf-8', 'Authorization' => 'XaxHyiIwhR06isYQGKHiei6J2ZuRsFzsgCJ4NucC',),
                'body' => json_encode($user)
            )
        );

        if ( is_wp_error( $response ) ) {
            $error_message = $response->get_error_message();
            echo "Something went wrong: $error_message";
        } else {
            print_r( $response );
        }
}

就像我从任务文本中了解的那样,向WP后端提交用户名/密码,然后我需要从WP后端(使用CURL或类似名称)向第三方网站提出身份验证请求...

有人可以给我说明如何进行制作,或者提供一些教程或示例。

php wordpress
1个回答
0
投票

请你能告诉我如何解决这个问题吗?谢谢

© www.soinside.com 2019 - 2024. All rights reserved.