• Resolved ireferpesa

    (@ireferpesa)


    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:

    const response = await fetch(ruta_api, {
    
    method:'GET',
    
    headers:{
    
    //'authorization': 'Bearer ' + token,
    
    authorization: 'Basic cm9pc2Nyb2xsOmQzczRycjBsbDAu',
    
    }
    
    });

    And this is the htaccess

    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

    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
    	https://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

    (@abhiladdha07)

    Hi @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 if you are using the Basic Auth from our plugin.

    Looking forward to your reply.

    Thanks,
    Team miniOrange

    Thread Starter ireferpesa

    (@ireferpesa)

    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.

     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.

    Access to fetch at 'https://xxxxxx/wp-json/wp/v2/pages' from origin 'https://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

    (@abhiladdha07)

    Hi @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

    (@ireferpesa)

    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

    (@abhiladdha07)

    Hi @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

    (@abhiladdha07)

    Hi @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.