服务器响应包含授权标头,但我在Vue应用中看不到它

时间:2019-10-25 08:19:21

标签: spring-boot vue.js heroku

我有使用REST服务的Vue应用程序(Spring Boot应用程序)。在服务中,身份验证是通过SpringSecurity实现的。跨源请求已启用。

在Vue应用中,我通过这种方式获得授权:

let credentialsUrl = "username=" + this.username + "&" + "password=" + this.password;
axios
    .post('https://bearings-info.herokuapp.com/login', credentialsUrl)
    .then(response => {
    if (response.status === 200) {
        let authorization = response.headers.authorization;
        this.$store.dispatch("setAuthorization", authorization);
    }
    });
}

在localhost上运行正常:我成功获取了Bearer令牌。

但是现在REST服务已部署到远程服务器(Heroku)。而且Vue对象响应不再包含授权。

为什么会这样?

其他#1:

console.log(JSON.stringify(response))方法的输出:

来自本地主机的响应,具有授权:

{“ data”:“”,“ status”:200,“ statusText”:“”,“ headers”:{“ pragma”:“ no-cache”,“ date”:“ Fri,25 Oct 2019 09 :17:06 GMT “ ”X-内容类型的选项“: ”nosniff“, ”服务器“: ”的nginx / 1.14.0(Ubuntu的)“, ”授权“:” 承载eyJ0b2tlblR5cGUiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJzZWN1cmUtYXBpIiwiYXVkIjoic2VjdXJlLWFwcCIsInN1YiI6ImFkbWluIiwiZXhwIjoxNTcyODU5MDI2LCJyb2xlcyI6WyJST0xFX0FETUlOIl19.1SBIxIIk0qkja05_6t3lmPIpBh58LajaMvdW-i9xkzqVZNSspJ- zQ9E07xVxut02QaxUx9oHeeap76mqL1PUhA“,” x-frame-options“:” DENY“,” access-control-allow-origin“:” *“,” cache-control“:” no-cache,no-store,max-age = 0,必须重新验证”,“连接”:“保持活动”,“内容长度”:“ 0”,“ x-xss保护”:“ 1;模式=阻止”,“过期”:“ 0”}, “ config”:{“ url”:“ / backend / login”,“ method”:“ post”,“ data”:“ username = admin&password = admin”,“ headers”:{“ Accept”:“ application / json, text / plain,/“,” Content-Type“:” application / x-www-form-urlencoded“},” transformRequest“:[null],” transformResponse“:[null],” timeout“:0,” xsrfCookieName “:” XSRF-TOKEN“,” xsrfHeaderName“:” X-XSRF-TO KEN“,” maxContentLength“:-1},” request“:{}}

来自远程服务器的响应,没有授权:

{“ data”:“”,“ status”:200,“ statusText”:“”,“ headers”:{“ pragma”:“ no-cache”,“ cache-control”:“ no-cache,无商店,最大年龄= 0,必须重新验证”,“过期”:“ 0”},“配置”:{“ url”:“ https://bearings-info.herokuapp.com/login”,“方法”:“发布”,“ data“:” username = admin&password = admin“,” headers“:{” Accept“:” application / json,text / plain,/“,” Content-Type“:” application / x-www-form-urlencoded“} ,“ transformRequest”:[null],“ transformResponse”:[null],“超时”:0,“ xsrfCookieName”:“ XSRF-TOKEN”,“ xsrfHeaderName”:“ X-XSRF-TOKEN”,“ maxContentLength”:- 1},“请求”:{}}

在Chrome控制台(网络,标头)中来自服务器的响应(以及来自本地主机的响应,以及来自Heroku的响应,两者均相同),具有授权:

授权:承载eyJ0b2tlblR5cGUiOiJKV1Qi ...

其他#2:

在客户端的Vue应用和localhost上的REST之间有nginx作为反向代理。客户端和远程REST之间没有nginx。也许那是原因吗?

0 个答案:

没有答案
相关问题