achievements-app / psn-api

A JavaScript library that lets you get trophy, user, and game data from the PlayStation Network.
https://psn-api.achievements.app
MIT License
263 stars 31 forks source link

Access to fetch has been blocked by CORS #153

Closed lindgrenkamali closed 7 months ago

lindgrenkamali commented 7 months ago

Hi!

I'm trying to use "exchangeNpssoForCode(npsso)" in my React application, but it doesn't work.

I'm getting the error "Access to fetch at 'https://ca.account.sony.com/api/authz/v3/oauth/authorize?access_type=offline&client_id=09515159-7237-4370-9b40-3806e67c0891&redirect_uri=com.scee.psxandroid.scecompcall%3A%2F%2Fredirect&response_type=code&scope=psn%3Amobile.v2.core+psn%3Aclientapp' from origin 'http://localhost:3000' has been blocked by CORS policy: 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."

Do you have any solution for this?

wescopeland commented 7 months ago

Unfortunately, Sony's CORS policy causes web browsers to block direct client-side calls to their API. You will need to set up some kind of middle layer (a Node.js service, Next.js API routes, etc) which makes the calls, and have your React app call that middle layer.