I am getting an error from generate token in google oauth API.
error:https://www.googleapis.com/oauth2/v3/token' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
fetch("https://www.googleapis.com/oauth2/v3/token", {
method: "POST",
headers: new Headers({
"Access-Control-Allow-Origin": window.location.origin,
"Access-Control-Allow-Methods": "DELETE, GET, POST, PUT",
"Access-Control-Allow-Header": "X-Requested-With,content-type",
"Access-Control-Allow-Credentials": true,
}),
body: JSON.stringify({
redirect_uri: redirect_uri,
client_secret: client_secret,
client_id: client_id,
refresh_token: refresh_token,
scope: scope,
grant_type: "refresh_token",
}),
})
.then((res) => res.json())
.then((res) => {
console.log(res);
localStorage.setItem("accessToken", res.access_token);
localStorage.setItem("refreshToken", res.refreshToken);
localStorage.setItem("expires_in", res.expires_in);
});