question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Same 401 CORS problem in OPTIONS with basic Auth in a GET request

See original GitHub issue

Hi, I’ve already read all issues about this problem and nothing worked for me. I’m trying to use Basic Auth with username and password but it always get 401 Unauthorized.

So I have this axios.js file, referenced in the main.js, to call it just using this.$http.


import Vue from 'vue'
import axios from 'axios'

Vue.use({
  install(Vue) {
    Vue.prototype.$http = axios.create({
      baseURL: 'https://b2b.crednosso.com.br/wsservicos/atm/',
      timeout: 1000,
      auth: {
        username:'username',
        password:'password'
      },
      headers: {'Access-Control-Allow-Origin': '*',
                'Access-Control-Allow-Credentials':'true',
              },
      withCredentials : true,
      crossDomain: true
    });
  }
})

I consume this api in another app using php and it works with no problem, but using axios with vuejs I get this

Access to XMLHttpRequest at ‘https://b2b.crednosso.com.br/wsservicos/atm/listarAtmEstadoCidade’ from origin ‘http://localhost:8080’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: It does not have HTTP ok status.

In my server I already have

responseBuilder.header("Access-Control-Allow-Origin", "*");
responseBuilder.header("Access-Control-Allow-Credentials", "true");
responseBuilder.header("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
responseBuilder.header("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, Authorization");

Someone can help me? The only solution that I’ve found is integrating with express or another framework.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13

github_iconTop GitHub Comments

2reactions
khamnhcommented, May 3, 2019

same here. +1

1reaction
atsoarescommented, May 6, 2019

Okay, in the backend of b2b.crednosso.com,br I already have this.

responseBuilder.header("Access-Control-Allow-Origin", "*"); responseBuilder.header("Access-Control-Allow-Credentials", "true"); responseBuilder.header("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT"); responseBuilder.header("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, Authorization");

So, this is not a server problem. As I guessed I just need to use a backend like express to use axios, because axios can’t be used only with vue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ajax CORS Request with http 401 in preflight - Stack Overflow
Your serverside requires HTTP Basic authentication for this request. And you don't provide credentials. 401 error has nothing to do with ...
Read more >
CORS and Basic authentication, error 401 - Camunda forum
And I try to set a GET request from my application with the following headers 'Content-Type': 'application/json', 'Authorization': "Basic ...
Read more >
Fixing 401s with CORS Preflights and Spring Security
In this short tutorial, we're going to learn how to solve the error “Response for preflight has invalid HTTP status code 401”, ...
Read more >
Cannot use CORS requests to REST API with preflight ...
This results in 401 response from the server and a failed request in the browser. This not sending credentials with preflight request and...
Read more >
Bypass authentication/authorization for OPTIONS requests ...
This is a CORS issue and happens because before the GET request is made, the browser will make an OPTIONS preflight request, which...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found