Title: 401 authenticate error
Last modified: February 24, 2023

---

# 401 authenticate error

 *  Resolved [ireferpesa](https://wordpress.org/support/users/ireferpesa/)
 * (@ireferpesa)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/401-authenticate-error/)
 * hello, I installed the plugin in wordpress and in the protected pages the options
   call returns a 401.
 * I make the calls in this way:
 *     ```wp-block-code
       const response = await fetch(ruta_api, {
   
       method:'GET',
   
       headers:{
   
       //'authorization': 'Bearer ' + token,
   
       authorization: 'Basic cm9pc2Nyb2xsOmQzczRycjBsbDAu',
   
       }
   
       });
       ```
   
 * And this is the htaccess
 *     ```wp-block-code
       Header set Access-Control-Allow-Methods "POST, GET, PUT, OPTIONS, PATCH, DELETE"
       Header set Access-Control-Allow-Origin "*"
       Header set Access-Control-Allow-Credentials "true"
       Header set Access-Control-Allow-Headers "X-Accept-Charset,X-Accept,Content-Type,Credentials"
       ```
   
 * And this is the response
 *     ```wp-block-code
       Estado
       401
       Unauthorized
       VersiónHTTP/2
       Transferido460 B (tamaño 0 B)
       Política de referenciastrict-origin-when-cross-origin
   
   
       access-control-allow-credentials
       	true
       access-control-allow-headers
       	X-Accept-Charset,X-Accept,Content-Type,Credentials
       access-control-allow-methods
       	POST, GET, PUT, OPTIONS, PATCH, DELETE
       access-control-allow-origin
       	*
       content-type
       	application/json; charset=UTF-8
       date
       	Fri, 24 Feb 2023 10:21:43 GMT
       server
       	nginx
       strict-transport-security
       	max-age=15768000; includeSubDomains
       X-Firefox-Spdy
       	h2
       x-powered-by
       	PHP/8.1.16
   
       Accept
       	*/*
       Accept-Encoding
       	gzip, deflate, br
       Accept-Language
       	es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3
       Access-Control-Request-Headers
       	authorization
       Access-Control-Request-Method
       	GET
       Connection
       	keep-alive
       Host
       	roiscroll.dev
       Origin
       	http://rs.test:3000
       Referer
       	http://rs.test:3000/
       Sec-Fetch-Dest
       	empty
       Sec-Fetch-Mode
       	cors
       Sec-Fetch-Site
       	cross-site
       User-Agent
       	Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/110.0
       ```
   

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Support [abhiladdha07](https://wordpress.org/support/users/abhiladdha07/)
 * (@abhiladdha07)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/401-authenticate-error/#post-16504879)
 * Hi [@ireferpesa](https://wordpress.org/support/users/ireferpesa/),
 * Thanks for reaching out.
 * To figure our the issue, can you please share the following?
    1. What is the exact error response you are getting?
    2. Were you able to do the Test Configuration successfully in our plugin?
 * The above detials will help us resolve the issues you are having.
 * You can find the code snippet **[here](https://plugins.miniorange.com/wordpress-rest-api-basic-authentication-method#samplecode)**
   if you are using the Basic Auth from our plugin.
 * Looking forward to your reply.
 * Thanks,
   Team miniOrange
 *  Thread Starter [ireferpesa](https://wordpress.org/support/users/ireferpesa/)
 * (@ireferpesa)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/401-authenticate-error/#post-16509348)
 * Hi,
 * from postman works correctly. The call from the external application fails.
   Among
   the example codes there is none that works for me, since the page is made in 
   svelte and I make the call from javascript.But I have tried to put the same variables
   as in the example.This is the call code, and the error.
 *     ```wp-block-code
        async function getCaso() {
               const response = await fetch(ruta_api, {
                   method:'POST',
                   timeout:0,
                   processData: false,
                   mimeType: "multipart/form-data",
                   contentType: false,
                   headers:{
                       //'authorization': 'Bearer ' + token,
                       authorization: 'Basic cm9pc2Nyb2xsOmQzczRycjBsbDAu',
                   }
               });
               const string = await response.text();
               const json = string === "" ? {} : JSON.parse(string);
               //console.log(json);
   
               //return await json;
   
               if (response.status === 200) {
                   return await response.json();
               } else {
                   console.log(response);
                   throw new Error('Error en la queryyyy');
               }
           }
       ```
   
 * 
   As you can see the error is in the precall of options because it sends the authenticated.
 *     ```wp-block-code
       Access to fetch at 'https://xxxxxx/wp-json/wp/v2/pages' from origin 'http://rs.test:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
       ```
   
 *  Plugin Support [abhiladdha07](https://wordpress.org/support/users/abhiladdha07/)
 * (@abhiladdha07)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/401-authenticate-error/#post-16511052)
 * Hi [@ireferpesa](https://wordpress.org/support/users/ireferpesa/),
 * Thanks for sharing the error response. It seems you are getting a CORS issue 
   which generally happens when you try to make the request from a JS-based framework(
   Client side) to the PHP-based WordPress APIs (Server Side).
 * You can add appropriate configuration rules in your WordPress server config file
   to remove this.
 * Please feel free to ask if you need any help on this.
 * Thanks,
   Team miniOrange
 *  Thread Starter [ireferpesa](https://wordpress.org/support/users/ireferpesa/)
 * (@ireferpesa)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/401-authenticate-error/#post-16511125)
 * could you please elaborate? I tried to add some CORS policies config lines through
   htaccess as I posted earlier, but to no avail
 *  Plugin Support [abhiladdha07](https://wordpress.org/support/users/abhiladdha07/)
 * (@abhiladdha07)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/401-authenticate-error/#post-16513748)
 * Hi [@ireferpesa](https://wordpress.org/support/users/ireferpesa/),
 * Thanks for the quick response.
 * The .htaccess configuration looks good, can we have a quick meet and screen share
   session to debug this and help you out?
 * If it works for you, then you can drop the query from the plugin support forum
   and mention the scenario so we can assign the technical engineers to set up the
   call and help you further.
 * Thanks,
   Team miniOrange
 *  Plugin Support [abhiladdha07](https://wordpress.org/support/users/abhiladdha07/)
 * (@abhiladdha07)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/401-authenticate-error/#post-16585679)
 * Hi [@ireferpesa](https://wordpress.org/support/users/ireferpesa/),
 * We haven’t heard back from you in the last couple of days, so we are marking 
   this thread as resolved. You can always post your queries on this forum if you
   have any questions or face issues with our plugin. We’d be happy to help you.
 * Thanks,
   Team miniOrange

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘401 authenticate error’ is closed to new replies.

 * ![](https://ps.w.org/wp-rest-api-authentication/assets/icon-128x128.png?rev=2084327)
 * [JWT Authentication for WP REST APIs](https://wordpress.org/plugins/wp-rest-api-authentication/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-rest-api-authentication/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-rest-api-authentication/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-rest-api-authentication/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-rest-api-authentication/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-rest-api-authentication/reviews/)

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)

 * 6 replies
 * 2 participants
 * Last reply from: [abhiladdha07](https://wordpress.org/support/users/abhiladdha07/)
 * Last activity: [3 years, 2 months ago](https://wordpress.org/support/topic/401-authenticate-error/#post-16585679)
 * Status: resolved