achievements-app/psn-api

Unable to get psn access code

landscht opened this issue · 6 comments

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

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:

  • The obvious: be extra sure you copied, pasted, and are using the correct NPSSO. Sometimes a special character is added by Sony to the end of the NPSSO string leading the whole thing not to be copied on a triple-click from the web browser. Hardcode your NPSSO as a string arg to the function instead of using an env var just to be sure.
  • Try an NPSSO from a completely brand new PSN account (this is a good idea honestly so your personal account doesn't get rate-limited)

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?

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)

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.

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.

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.