Basic Authentication problem with custom API endpoints

If you’re looking at actual “basic authentication”, check out the Basic Auth plugin. Note that it’s for the REST API plugin, not the core implementation, so you’ll need to adjust some filters.

If you’re looking for authentiction for the current user based on their current cookies in the browser, the REST API has that built in, you’ll just need to pass a X-WP-Nonce header with your HTTP request.

You can learn more here: http://v2.wp-api.org/guide/authentication/

Hope that helps!