MCPcopy Index your code
hub / github.com/WP-API/node-wpapi / _auth

Function _auth

lib/http-transport.js:46–69  ·  view source on GitHub ↗

* Conditionally set basic authentication on a server request object. * * @method _auth * @private * @param {Object} request A superagent request object * @param {Object} options A WPRequest _options object * @param {Boolean} forceAuthentication whether to force authentication on the request *

( request, options, forceAuthentication )

Source from the content-addressed store, hash-verified

44 * @param {Object} A superagent request object, conditionally configured to use basic auth
45 */
46function _auth( request, options, forceAuthentication ) {
47 // If we're not supposed to authenticate, don't even start
48 if ( ! forceAuthentication && ! options.auth && ! options.nonce ) {
49 return request;
50 }
51
52 // Enable nonce in options for Cookie authentication http://wp-api.org/guides/authentication.html
53 if ( options.nonce ) {
54 request.set( 'X-WP-Nonce', options.nonce );
55 return request;
56 }
57
58 // Retrieve the username & password from the request options if they weren't provided
59 const username = options.username;
60 const password = options.password;
61
62 // If no username or no password, can't authenticate
63 if ( ! username || ! password ) {
64 return request;
65 }
66
67 // Can authenticate: set basic auth parameters on the request
68 return request.auth( username, password );
69}
70
71// Pagination-Related Helpers
72// ==========================

Callers 5

_httpGetFunction · 0.85
_httpPostFunction · 0.85
_httpPutFunction · 0.85
_httpDeleteFunction · 0.85
_httpHeadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected