How to do Basic Authentication from React Axios GET call to a SpringBoot microservice

Viewed 1888

Postman Request Details enter image description here I am using axios.get() to call a secured SpringBoot Microservice but it returns a 401 Unauthorized response. Postman returns the output as expected for SpringBoot Microservice but not the React App

I have tried all the possibilities available on internet but in vain.

Please help me get a solution to this.

React Call: passing auth as parameter as it is the way to do Basic Authentication in Axios

    axios.get('http://localhost:8080/hellouser/greet/',
     {},
    {auth:{
        username:'demouser',
        password:'demopassword'
        }}).then(function (response) {
console.log(response);
  })
1 Answers

Try this approach instead

axios.get('http://localhost:8080/hellouser/greet/', {
    params: {},
    withCredentials: true,
    auth: {
        username: 'myusername',
        password: 'mypassword'
    }
})

You might also check the version of the library. It may vary from one to another

Related