Completed
Branch rest-authorization (c7240a)
by
unknown
18:33 queued 15:01
created
core/libraries/rest_api/Authorization.php 2 patches
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -6,75 +6,75 @@
 block discarded – undo
6 6
 
7 7
 class Authorization
8 8
 {
9
-    /**
10
-     * @var WP_REST_Request
11
-     */
12
-    protected $request;
9
+	/**
10
+	 * @var WP_REST_Request
11
+	 */
12
+	protected $request;
13 13
 
14 14
 
15
-    public static function verifyAccess(WP_REST_Request $request)
16
-    {
17
-        // $headers = $request->get_headers();
18
-        // foreach ($headers as $key => $header) {
19
-        //     EEH_Debug_Tools::printr($header, $key, __FILE__, __LINE__);
20
-        // }
21
-        echo "\n";
15
+	public static function verifyAccess(WP_REST_Request $request)
16
+	{
17
+		// $headers = $request->get_headers();
18
+		// foreach ($headers as $key => $header) {
19
+		//     EEH_Debug_Tools::printr($header, $key, __FILE__, __LINE__);
20
+		// }
21
+		echo "\n";
22 22
 
23
-        // if (is_readable(EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php')) {
24
-        //     $auth_header = $headers['Authorization'] ?? [];
25
-        //     // \EEH_Debug_Tools::printr($auth_header, '$auth_header', __FILE__, __LINE__);
26
-        //     if (Authorization::basicAuthentication($auth_header)) {
27
-        //         return true;
28
-        //     }
29
-        // }
23
+		// if (is_readable(EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php')) {
24
+		//     $auth_header = $headers['Authorization'] ?? [];
25
+		//     // \EEH_Debug_Tools::printr($auth_header, '$auth_header', __FILE__, __LINE__);
26
+		//     if (Authorization::basicAuthentication($auth_header)) {
27
+		//         return true;
28
+		//     }
29
+		// }
30 30
 
31
-        // if (class_exists('Jwt_Auth')){
32
-        //     $auth_headers = $headers['Authorization'] ?? [];
33
-        // }
31
+		// if (class_exists('Jwt_Auth')){
32
+		//     $auth_headers = $headers['Authorization'] ?? [];
33
+		// }
34 34
 
35
-        if (class_exists('Miniorange_Api_Authentication')){
36
-            // $auth_header = $headers['Authorization'] ?? [];
37
-            // if (Authorization::basicAuthentication($auth_header)) {
38
-            //     return true;
39
-            // }
40
-            Authorization::jwtAuthentication();
41
-        }
42
-        // throw new RuntimeException(
43
-        //     esc_html__('Authorization required to access REST API routes.', 'event_espresso')
44
-        // );
45
-    }
35
+		if (class_exists('Miniorange_Api_Authentication')){
36
+			// $auth_header = $headers['Authorization'] ?? [];
37
+			// if (Authorization::basicAuthentication($auth_header)) {
38
+			//     return true;
39
+			// }
40
+			Authorization::jwtAuthentication();
41
+		}
42
+		// throw new RuntimeException(
43
+		//     esc_html__('Authorization required to access REST API routes.', 'event_espresso')
44
+		// );
45
+	}
46 46
 
47 47
 
48
-    private static function basicAuthentication($auth_header): bool
49
-    {
50
-        return is_string($auth_header) && strpos($auth_header, 'Basic') === 0;
51
-    }
48
+	private static function basicAuthentication($auth_header): bool
49
+	{
50
+		return is_string($auth_header) && strpos($auth_header, 'Basic') === 0;
51
+	}
52 52
 
53
-    private static function jwtAuthentication()
54
-    {
55
-        $route = site_url(rest_get_url_prefix() . '/api/v1/token?mo_rest_api_test_config=jwt_auth');
56
-        \EEH_Debug_Tools::printr($route, '$route', __FILE__, __LINE__);
57
-        echo "\n";
58
-        $post_data = [
59
-            'username' => 'bc',
60
-            'password' => 'bc',
61
-        ];
62
-        $request = new WP_REST_Request('POST', $route);
63
-        $request->set_body_params($post_data);
64
-        $response = rest_do_request($request);
65
-        \EEH_Debug_Tools::printr($response, '$response', __FILE__, __LINE__);
66
-        echo "\n";
67
-        // if ($response->is_error()) {
68
-        //     $error = $response->as_error();
69
-        //     throw new RuntimeException(
70
-        //         sprintf(
71
-        //             esc_html__('Authorization required to access REST API routes: %1$s', 'event_espresso'),
72
-        //             $error->get_error_message()
73
-        //         )
74
-        //     );
75
-        // }
76
-        $data = $response->get_data();
77
-        \EEH_Debug_Tools::printr($data, '$data', __FILE__, __LINE__);
78
-        echo "\n\n";
79
-    }
53
+	private static function jwtAuthentication()
54
+	{
55
+		$route = site_url(rest_get_url_prefix() . '/api/v1/token?mo_rest_api_test_config=jwt_auth');
56
+		\EEH_Debug_Tools::printr($route, '$route', __FILE__, __LINE__);
57
+		echo "\n";
58
+		$post_data = [
59
+			'username' => 'bc',
60
+			'password' => 'bc',
61
+		];
62
+		$request = new WP_REST_Request('POST', $route);
63
+		$request->set_body_params($post_data);
64
+		$response = rest_do_request($request);
65
+		\EEH_Debug_Tools::printr($response, '$response', __FILE__, __LINE__);
66
+		echo "\n";
67
+		// if ($response->is_error()) {
68
+		//     $error = $response->as_error();
69
+		//     throw new RuntimeException(
70
+		//         sprintf(
71
+		//             esc_html__('Authorization required to access REST API routes: %1$s', 'event_espresso'),
72
+		//             $error->get_error_message()
73
+		//         )
74
+		//     );
75
+		// }
76
+		$data = $response->get_data();
77
+		\EEH_Debug_Tools::printr($data, '$data', __FILE__, __LINE__);
78
+		echo "\n\n";
79
+	}
80 80
 }
81 81
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
         //     $auth_headers = $headers['Authorization'] ?? [];
33 33
         // }
34 34
 
35
-        if (class_exists('Miniorange_Api_Authentication')){
35
+        if (class_exists('Miniorange_Api_Authentication')) {
36 36
             // $auth_header = $headers['Authorization'] ?? [];
37 37
             // if (Authorization::basicAuthentication($auth_header)) {
38 38
             //     return true;
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 
53 53
     private static function jwtAuthentication()
54 54
     {
55
-        $route = site_url(rest_get_url_prefix() . '/api/v1/token?mo_rest_api_test_config=jwt_auth');
55
+        $route = site_url(rest_get_url_prefix().'/api/v1/token?mo_rest_api_test_config=jwt_auth');
56 56
         \EEH_Debug_Tools::printr($route, '$route', __FILE__, __LINE__);
57 57
         echo "\n";
58 58
         $post_data = [
Please login to merge, or discard this patch.