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
265 stars 33 forks source link

Need some guidance #45

Closed robiningelbrecht closed 2 years ago

robiningelbrecht commented 2 years ago

So I feel really stupid, but is this package useable in plain javascript? Or do I need to run a node.js server and use TypeScript? I can't seem to get this to work with JS only...

robiningelbrecht commented 2 years ago

So, I was able to import the modules in a react project, but when I try to 'exchangeNpssoForCode', I get CORS errors:

Access to fetch at 'https://ca.account.sony.com/api/authz/v3/oauth/authorize?access_type=offline&client_id=ac8d161a-d966-4728-b0ea-ffec22f69edc&redirect_uri=com.playstation.PlayStationApp%3A%2F%2Fredirect&response_type=code&scope=psn%3Amobile.v1+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.

wescopeland commented 2 years ago

Hi @robiningelbrecht!

Yes the project is usable with plain JavaScript :-)

For the 2nd question, I do not recommend executing the exchangeNpssoForCode function client-side. This implies that your NPSSO is being stored client-side (aka: public), which is as good as exposing your password publicly.

If you still want to use your NPSSO, I recommend wrapping it in a custom API endpoint so it is not exposed. This should also conveniently get around the CORS issue you are facing.

wescopeland commented 2 years ago

If any more support is needed here please LMK! Otherwise I’ll close this for now.