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

Unable to get psn access code #108

Closed landscht closed 1 year ago

landscht commented 1 year ago

I have the same problem as issue #105 with a freshly generated npsso code and it is impossible to exchange it for an access code. my application uses ionic and I'm on angular. For my tests I did it from my browser in which I am well connected to Playstation and I get the NSSO via the link specified in your documentation via the same browser. Here is the exact error that exchangeNpssoForCode returns: GET 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 403 (Forbidden)

Error: Uncaught (in promise): Error: 
      There was a problem retrieving your PSN access code. Is your NPSSO code valid?
      To get a new NPSSO code, visit https://ca.account.sony.com/api/v1/ssocookie.

Thank you for all

wescopeland commented 1 year ago

Hi @landscht ,

Thanks for using psn-api. I am actively using the latest version of psn-api on a daily basis and am currently unable to reproduce this issue. To be sure, I exchanged an NPSSO for an access code seconds before making this post.

A 403 error from PSN leads me to believe the NPSSO being used is somehow invalid. There are a few things you can try:

landscht commented 1 year ago

Hi @wescopeland,

I created a new account, retrieved the NPSSO code, I hard-coded it to the exchangeNpssoForCode method and I have exactly the same problem. Is it necessary to have playstation connection cookies to call the exchangeNpssoForCode method?

wescopeland commented 1 year ago

Hi @landscht ,

It is not necessary to have the PlayStation connection cookies to call this or any other method.

Can you please do me a favor? Try using this NPSSO and see what happens:

-

(I am trying to determine if locale where the NPSSO is generated has any influence on the method working)

wescopeland commented 1 year ago

Another thought -- I think this is not NPSSO related. Can you check your network tab while the Angular app is open on localhost and see the response coming back from Sony's servers. This could actually be a CORS error that psn-api is blanket-reporting as an NPSSO problem. Most of us are using psn-api server-side (or in Next.js's getServerSideProps() et al) and not from a SPA.

landscht commented 1 year ago

I went through a node server to use your api and it just happens to work. It must be a cors error but it's weird that it's not specified in the http error or in the request logs. Thank you for all your help.

wescopeland commented 1 year ago

No problem & sorry for the confusion. Yes, it must be a CORS error. The library should do a better job of informing the user if a CORS error happens when trying to exchange the NPSSO; I will add this functionality.