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

403 error and blocked by CORS policy #146

Closed fredhua233 closed 11 months ago

fredhua233 commented 1 year ago

Hi I'm trying to use the psn-api to make an web app that displays psn user's achievement. I've been following the steps from the documentation to get my npsso code and generate access code with it but I kept running into errors in the photo.

Steps taken to fix(taken from various stackoverflow articles):

  1. adding { mode: "no-cors" } to the response header
  2. adding { Access-Control-Allow-Origin: * } to the response header
  3. adding { Access-Control-Allow-Origin: http://localhost:3000 } to the response header

Steps to reproduce:

  1. follow the documentation on authentication
  2. calling the exchangeNpssoForCode(myNpssoToken) from your application

I know this is a newbie issue but I really need this to work, so any feedback helps.

Screenshot 2023-08-15 at 4 14 31 PM
wescopeland commented 1 year ago

Hi @fredhua233,

This is the browser not continuing with the API calls because Sony doesn't allow their resources to explicitly be available to your server. Unfortunately, that is normal.

The best way to get around this is to set up a server with Node.js which uses psn-api, and have your front-end make calls to that server's endpoints instead.