Home HTTP GET with basic auth works from server (nodejs) but not from client (React)
Reply: 0

HTTP GET with basic auth works from server (nodejs) but not from client (React)

Jack M.
1#
Jack M. Published in 2018-01-13 12:02:23Z

I stumbled upon a strange error when trying to GET data from 3rd party REST API with my React client.

Im using request-promise as the http-request library. When I do this with node.js it works and returns correct data =>

const auth = {
    username: 'USER',
    password: 'PASS'
};

const checkIfDeviceExists = await request.get({
    url: 'https://apiurl',
    auth
});

But when I try the same with React it just returns error =>

The SSL certificate used to load resources from https://apiurl will be distrusted in M70. Once distrusted, users will be prevented from loading these resources. See https://g.co/chrome/symantecpkicerts for more information.

and

Failed to load https://apiurl: Response for preflight has invalid HTTP status code 401

I also tried with fetch, but same error =>

fetch('https://apiurl', {
    method: 'get',
    headers: {
        'Authorization': 'Basic '+ btoa('USER:PASS')            }
});

Am I doing the authentication wrong or is there something I dont know about http-requests with server vs client? The api says in documentation that it's using basic auth.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.376667 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO