Tmeister / wp-api-jwt-auth

A simple plugin to add JSON Web Token (JWT) Authentication to WP REST API
GNU General Public License v2.0
558 stars 161 forks source link

add_filter causes php_network_getaddresses: getaddrinfo failed: Name or service not known #134

Closed flolege closed 5 years ago

flolege commented 5 years ago

I installed JWT according to the instruction and tested the /wp-json/jwt-auth/v1/token restpoint via POSTMAN. But I get this response here:

Connection failed: _php_networkgetaddresses: getaddrinfo failed: Name or service not known In Wordpress the log says:

mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known (357) : eval()'d code

pointing to wp-content/plugins/code-snippets/php/snippet-ops.php

It seems it has to do with adding a filter. When I deactivate the filter, the restpoint works again. I use the plugin "Code Snippets" for that. Here is the extension with the commented out filter:

function extend_token( $data, $user ) {

  $isProvider = get_user_meta($user->ID, "isProvider", true); 

  if($isProvider == true)
  {
    $data['isProvider'] = 'true';
    $profileData = get_profile_data_by_userId($user->ID);
    $data = array_merge($data, $profileData); 
    $unitData = get_unit_data_by_userId($user->ID);
    $data = array_merge($data, $unitData); 
    $offerData = get_offer_data_by_userId($user->ID);
    $data = array_merge($data, $offerData);     
    $eventData = get_event_data_by_userId($user->ID);
    $data = array_merge($data, $eventData);         
  }  
    return $data;  
}
//add_filter( 'jwt_auth_token_before_dispatch', 'extend_token', 10, 2 );

BTW: /wp-json/jwt-auth/v1/token/validate endpoint works normal.

flolege commented 5 years ago

I found the issue, the extend_token function called other sub functions which contained database connections with invalid parameters.