【发布时间】:2020-08-05 09:49:46
【问题描述】:
我按照这个从刷新令牌中获取令牌:https://firebase.google.com/docs/reference/rest/auth/#section-refresh-token
let response = await axios.post(`https://securetoken.googleapis.com/v1/token?key=${FIREBASE_CONFIG.apiKey}&grant_type=refresh_token&refresh_token=${refreshToken}`,
{}, {
data: qs,
headers: { "content-type": "application/x-www-form-urlencoded" }
}
);
它过去可以工作,但现在无法正常工作。 在 Chrome 控制台中出现此错误:
从源“http://localhost:8080”访问位于“https://securetoken.googleapis.com/v1/token?key=&grant_type=refresh_token&refresh_token=”的 XMLHttpRequest 已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:否“Access-Control-Allow-”请求的资源上存在 Origin' 标头。
【问题讨论】:
-
axios 向请求中添加了哪些其他标头?通过检查 devtools 的网络窗格中的请求来检查。更改您的前端代码以删除 axios 添加的任何其他标头。或者改为使用
fetch()发出请求,这使您可以直接完全控制标头。我这么说是因为问题中的错误表明浏览器正在执行 CORS 预检 OPTIONS 请求,并且只有content-type: application/x-www-form-urlencoded标头的 POST 到https://firebase.google.com/docs/reference/rest/auth/#section-refresh-token不会触发预检
标签: firebase google-chrome google-api firebase-authentication cors