assets
1 day ago
format
1 day ago
helpers
1 day ago
class-ajax-passkeys.php
1 day ago
class-api-register.php
1 day ago
class-api-signin.php
1 day ago
class-attestation-object.php
1 day ago
class-authenticate-server.php
1 day ago
class-authenticator-data.php
1 day ago
class-byte-buffer.php
1 day ago
class-chor-decoder.php
1 day ago
class-passkeys-endpoints.php
1 day ago
class-passkeys-user-profile.php
1 day ago
class-passkeys-wizard-steps.php
1 day ago
class-passkeys.php
1 day ago
class-pending-2fa-helper.php
1 day ago
class-source-repository.php
1 day ago
class-web-authn-exception.php
1 day ago
class-web-authn.php
1 day ago
index.php
1 day ago
class-passkeys-endpoints.php
156 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Responsible for the API endpoints |
| 4 | * |
| 5 | * @package wp-2fa |
| 6 | * @since 3.0.0 |
| 7 | * @copyright 2026 Melapress |
| 8 | * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 |
| 9 | * @link https://wordpress.org/plugins/wp-2fa/ |
| 10 | */ |
| 11 | |
| 12 | declare(strict_types=1); |
| 13 | |
| 14 | namespace WP2FA\Passkeys; |
| 15 | |
| 16 | use WP2FA\Passkeys\API_Signin; |
| 17 | use WP2FA\Passkeys\API_Register; |
| 18 | use WP2FA\Admin\Controllers\Endpoints; |
| 19 | |
| 20 | defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
| 21 | |
| 22 | /** |
| 23 | * Endpoints registering |
| 24 | */ |
| 25 | if ( ! class_exists( '\WP2FA\Passkeys\PassKeys_Endpoints' ) ) { |
| 26 | |
| 27 | /** |
| 28 | * Creates and registers all the API endpoints for the proxytron |
| 29 | * |
| 30 | * @since 3.0.0 |
| 31 | */ |
| 32 | class PassKeys_Endpoints { |
| 33 | |
| 34 | /** |
| 35 | * All of the endpoints supported by the plugin. |
| 36 | * |
| 37 | * @var array |
| 38 | * |
| 39 | * @since 3.0.0 |
| 40 | */ |
| 41 | public static $endpoints = array( |
| 42 | self::class => array( |
| 43 | 'register' => array( |
| 44 | 'class' => API_Register::class, |
| 45 | 'namespace' => 'wp-2fa-passkeys/v1', |
| 46 | |
| 47 | 'endpoints' => array( |
| 48 | array( |
| 49 | 'request' => array( |
| 50 | 'methods' => array( |
| 51 | 'method' => \WP_REST_Server::CREATABLE, |
| 52 | 'callback' => 'register_request_action', |
| 53 | ), |
| 54 | 'checkPermissions' => array( |
| 55 | Endpoints::class, |
| 56 | 'check_permissions', |
| 57 | ), |
| 58 | 'showInIndex' => false, |
| 59 | ), |
| 60 | ), |
| 61 | array( |
| 62 | 'response' => array( |
| 63 | 'methods' => array( |
| 64 | 'method' => \WP_REST_Server::CREATABLE, |
| 65 | 'callback' => 'register_response_action', |
| 66 | ), |
| 67 | 'checkPermissions' => array( |
| 68 | Endpoints::class, |
| 69 | 'check_permissions', |
| 70 | ), |
| 71 | 'showInIndex' => true, |
| 72 | ), |
| 73 | ), |
| 74 | array( |
| 75 | 'revoke' => array( |
| 76 | 'methods' => array( |
| 77 | 'method' => \WP_REST_Server::CREATABLE, |
| 78 | 'callback' => 'register_revoke_action', |
| 79 | ), |
| 80 | 'checkPermissions' => array( |
| 81 | Endpoints::class, |
| 82 | 'check_permissions', |
| 83 | ), |
| 84 | 'showInIndex' => false, |
| 85 | ), |
| 86 | ), |
| 87 | array( |
| 88 | 'enable' => array( |
| 89 | 'methods' => array( |
| 90 | 'method' => \WP_REST_Server::CREATABLE, |
| 91 | 'callback' => 'register_enable_action', |
| 92 | ), |
| 93 | 'checkPermissions' => array( |
| 94 | Endpoints::class, |
| 95 | 'check_permissions', |
| 96 | ), |
| 97 | 'showInIndex' => false, |
| 98 | ), |
| 99 | ), |
| 100 | ), |
| 101 | ), |
| 102 | 'singin' => array( |
| 103 | 'class' => API_Signin::class, |
| 104 | 'namespace' => 'wp-2fa-passkeys/v1', |
| 105 | |
| 106 | 'endpoints' => array( |
| 107 | array( |
| 108 | 'request' => array( |
| 109 | 'methods' => array( |
| 110 | 'method' => \WP_REST_Server::CREATABLE, |
| 111 | 'callback' => 'signin_request_action', |
| 112 | ), |
| 113 | 'parameters' => array( |
| 114 | 'user' => array( |
| 115 | 'description' => 'Username or email of the user trying to sign in.', |
| 116 | 'type' => 'string', |
| 117 | 'required' => true, |
| 118 | ), |
| 119 | ), |
| 120 | 'checkPermissions' => '__return_true', |
| 121 | 'showInIndex' => false, |
| 122 | ), |
| 123 | ), |
| 124 | array( |
| 125 | 'response' => array( |
| 126 | 'methods' => array( |
| 127 | 'method' => \WP_REST_Server::CREATABLE, |
| 128 | 'callback' => 'signin_response_action', |
| 129 | ), |
| 130 | 'checkPermissions' => '__return_true', |
| 131 | 'showInIndex' => false, |
| 132 | ), |
| 133 | ), |
| 134 | ), |
| 135 | ), |
| 136 | ), |
| 137 | ); |
| 138 | |
| 139 | /** |
| 140 | * Inits all the endpoints from given structure |
| 141 | * |
| 142 | * @return void |
| 143 | * |
| 144 | * @since 3.0.0 |
| 145 | */ |
| 146 | public static function init() { |
| 147 | \add_filter( |
| 148 | WP_2FA_PREFIX . 'api_endpoints', |
| 149 | function ( $endpoints ) { |
| 150 | return array_merge( $endpoints, self::$endpoints ); |
| 151 | } |
| 152 | ); |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 |