@@ -27,21 +27,33 @@ class WP_JSON_Authentication_OAuth1_Authorize {
27
27
* Register required actions and filters
28
28
*/
29
29
public function register_hooks () {
30
- add_action ( 'login_form_oauth1_authorize ' , array ( $ this , 'render_page ' ) );
30
+ add_action ( 'login_form_oauth1_authorize ' , array ( $ this , 'handle_request ' ) );
31
31
add_action ( 'oauth1_authorize_form ' , array ( $ this , 'page_fields ' ) );
32
32
}
33
33
34
+ /**
35
+ * Handle request to authorization page
36
+ *
37
+ * Handles response from {@see render_page}, then exits to avoid output from
38
+ * default wp-login handlers.
39
+ */
40
+ public function handle_request () {
41
+ $ response = $ this ->render_page ();
42
+ if ( is_wp_error ( $ response ) ) {
43
+ $ this ->display_error ( $ response );
44
+ }
45
+ exit ;
46
+ }
47
+
34
48
/**
35
49
* Render authorization page
36
50
*
37
- * Callback for login form hook. Must exit.
51
+ * @return null|WP_Error Null on success, error otherwise
38
52
*/
39
53
public function render_page () {
40
54
// Check required fields
41
55
if ( empty ( $ _REQUEST ['oauth_token ' ] ) ) {
42
- $ error = new WP_Error ( 'json_oauth1_missing_param ' , sprintf ( __ ( 'Missing parameter %s ' ), 'oauth_token ' ), array ( 'status ' => 400 ) );
43
- $ this ->display_error ( $ error );
44
- exit ;
56
+ return new WP_Error ( 'json_oauth1_missing_param ' , sprintf ( __ ( 'Missing parameter %s ' ), 'oauth_token ' ), array ( 'status ' => 400 ) );
45
57
}
46
58
47
59
// Set up fields
@@ -55,8 +67,7 @@ public function render_page() {
55
67
$ errors = array ();
56
68
$ this ->token = $ authenticator ->get_request_token ( $ token_key );
57
69
if ( is_wp_error ( $ this ->token ) ) {
58
- $ this ->display_error ( $ this ->token );
59
- exit ;
70
+ return $ this ->token ;
60
71
}
61
72
62
73
// Fetch consumer
@@ -69,23 +80,20 @@ public function render_page() {
69
80
case 'authorize ' :
70
81
$ verifier = $ authenticator ->authorize_request_token ( $ this ->token ['key ' ] );
71
82
if ( is_wp_error ( $ verifier ) ) {
72
- $ this ->display_error ( $ error );
73
- exit ;
83
+ return $ verifier ;
74
84
}
75
85
76
86
$ error = $ this ->handle_callback_redirect ( $ verifier );
77
87
if ( is_wp_error ( $ error ) ) {
78
- $ this -> display_error ( $ error ) ;
88
+ return $ error ;
79
89
}
80
- exit ;
90
+ return null ;
81
91
82
92
case 'cancel ' :
83
93
exit ;
84
94
85
95
default :
86
- $ error = new WP_Error ( 'json_oauth1_invalid_action ' , __ ( 'Invalid authorization action ' ), array ( 'status ' => 400 ) );
87
- $ this ->display_error ( $ error );
88
- exit ;
96
+ return new WP_Error ( 'json_oauth1_invalid_action ' , __ ( 'Invalid authorization action ' ), array ( 'status ' => 400 ) );
89
97
}
90
98
}
91
99
@@ -95,8 +103,6 @@ public function render_page() {
95
103
}
96
104
97
105
include $ file ;
98
-
99
- exit ;
100
106
}
101
107
102
108
/**
0 commit comments