2021-02-25

Fetch API redirect doesn't work as i intended

Hello fellow stack overflowers! I'm building a small app with the use of battle.net api.

I'm trying to authenticate to the api using Oauth with fetch API but it doesn't seem to do what i want!

So this is my code ```

const authUrl =
  "https://eu.battle.net/oauth/authorize?client_id="clientid"&scope=wow.profile&state="state"&redirect_uri=https://localhost:3000/&response_type=code";
fetch(authUrl, {
  method:"GET"
  redirect: "follow",
  mode: "no-cors",
});

and it's supposed to redirect me back here https://localhost:3000/?code="code"&state="state" With the code being the actual auth code.

But when i try call that endpoint it dosnt redirect me back. From the developer console i can see that it does infact do a call here https://eu.battle.net/oauth/authorize?client_id="clientid"&scope=wow.profile&state="state"&redirect_uri=https://localhost:3000/&response_type=code which gives status 302. and then redirects me to this url:

https://eu.battle.net/login/en/?ref=https://eu.battle.net/oauth/authorize?client_id%3"clientId"%26scope%3Dwow.profile%26state%3Dsdagdf324asdas%26redirect_uri%3Dhttps://localhost:3000%26response_type%3Dcode&app=oauth which gives a status 200.

But not back to localhost. BUT if i paste the authUrl directly into the browser it does work as intended.

What am i doing wrong inside react?

Sorry if i'm being unclear or confusing. If i left any important stuff out just ask and i will provide! If anyone could try and help me it would be greatly appreciated! Thanks in Advance!



from Recent Questions - Stack Overflow https://ift.tt/3dPNwJ3
https://ift.tt/eA8V8J

No comments:

Post a Comment