Skip to content

Commit fc107b8

Browse files
committed
CI-6000: Expose Refresh Token in Authenticated REST API requests
--- Code review update. . .only expose for SSL requests _or_ for GRAPHQL_DEBUG requests
1 parent 59a1469 commit fc107b8

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/ManageTokens.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,20 @@ public static function use_custom_user_expiration( $expiration ) {
293293
*/
294294
public static function add_tokens_to_graphql_response_headers( $headers ) {
295295

296+
$should_return_tokens = false;
297+
298+
/**
299+
* If the request _is_ SSL, or GRAPHQL_DEBUG is defined, return the tokens
300+
* otherwise do not return them.
301+
*/
302+
if ( is_ssl() || defined( 'GRAPHQL_DEBUG' ) && true !== GRAPHQL_DEBUG ) {
303+
$should_return_tokens = true;
304+
}
305+
306+
if ( ! $should_return_tokens ) {
307+
return $headers;
308+
}
309+
296310
/**
297311
* If there's a Refresh-Authorization token in the request headers, validate it
298312
*/
@@ -344,6 +358,20 @@ public static function add_tokens_to_graphql_response_headers( $headers ) {
344358
*/
345359
public static function add_auth_headers_to_rest_response( \WP_HTTP_Response $response, $handler, $request ) {
346360

361+
$should_return_tokens = false;
362+
363+
/**
364+
* If the request _is_ SSL, or GRAPHQL_DEBUG is defined, return the tokens
365+
* otherwise do not return them.
366+
*/
367+
if ( is_ssl() || defined( 'GRAPHQL_DEBUG' ) && true !== GRAPHQL_DEBUG ) {
368+
$should_return_tokens = true;
369+
}
370+
371+
if ( ! $should_return_tokens ) {
372+
return $response;
373+
}
374+
347375
/**
348376
* Note: The Access-Control-Expose-Headers aren't directly filterable
349377
* for REST API responses, so this overrides them altogether.

0 commit comments

Comments
 (0)