Skip to content

Commit

Permalink
Add JSON Content-Type header for Auth0 endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcanhelp committed Jan 8, 2019
1 parent 0f943c2 commit ef5fd12
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/WP_Auth0_Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function custom_requests( $wp, $return = false ) {
return false;
}

$json_header = true;
switch ( $page ) {
case 'oauth2-config':
$output = wp_json_encode( $this->oauth2_config() );
Expand All @@ -88,7 +89,8 @@ public function custom_requests( $wp, $return = false ) {
$output = wp_json_encode( $this->migration_ws_get_user() );
break;
case 'coo-fallback':
$output = $this->coo_fallback();
$json_header = false;
$output = $this->coo_fallback();
break;
default:
return false;
Expand All @@ -98,10 +100,27 @@ public function custom_requests( $wp, $return = false ) {
return $output;
}

if ( $json_header ) {
add_filter( 'wp_headers', array( $this, 'add_json_header' ) );
$wp->send_headers();
}

echo $output;
exit;
}

/**
* Use with the wp_headers filter to add a Content-Type header for JSON output.
*
* @param array $headers - Existing headers to modify.
*
* @return mixed
*/
public function add_json_header( array $headers ) {
$headers['Content-Type'] = 'application/json; charset=' . get_bloginfo( 'charset' );
return $headers;
}

protected function coo_fallback() {
$protocol = $this->a0_options->get( 'force_https_callback', false ) ? 'https' : null;
return sprintf(
Expand Down

0 comments on commit ef5fd12

Please # to comment.