Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It still works? #54

Closed
appache7-2 opened this issue Dec 16, 2017 · 36 comments
Closed

It still works? #54

appache7-2 opened this issue Dec 16, 2017 · 36 comments

Comments

@appache7-2
Copy link

appache7-2 commented Dec 16, 2017

Still no idea?

{"error":"invalid_token","error_description":"Invalid token","error_code":4097,"docs":"https://auth.api.sonyentertainmentnetwork.com/docs/","parameters":["captchatokenmissing"]}

@ikrasnykh
Copy link

+1. Any workarounds?

@bozzit
Copy link
Contributor

bozzit commented Jan 23, 2018

Ya still works, and a work around. Let me know if you still need help

@BonkAssetReader
Copy link

@bozzit is there any way to make it a faster process or anything also, how can i contact you?

@ikrasnykh
Copy link

I may need help. I am not able to make it work and I assume it’s because of the recent change they did when added CAPTCHA

@bozzit
Copy link
Contributor

bozzit commented Jan 25, 2018

Yes the CAPTCHA stuff has messed things up for us here is the workaround.

https://www.bungie.net/en/User/SignIn/Psnid?code=000000

This link allows you to link your PSN account to your Bungie one.

Once authenticated and on the 2FA screen collect the URL will look something like:

https://auth.api.sonyentertainmentnetwork.com/signin/#/signin2sv/code?response_type=code&client_id=78420c74-1fdf-4575-b43f-eb94c7d770bf&redirect_uri=https%3A%2F%2Fwww.bungie.net%2Fen%2FUser%2FSignIn%2FPsnid&scope=psn:s2s&request_locale=en&state=830954072847926547&ticket_uuid=7e7cf194-817d-4001-b373-8c54c0da007e&layout_type=popup&entry=%2Fsignin2sv%2Fcode

Collect the ticket_uid, and DO NOT enter the 2FA code you should of received on your phone.

Using the following code:

try
{
   $account = new \PSN\Auth('yourpsnaccount@yourdomain.com',
                            'yourpsnpassword',
                            '7e7cf194-817d-4001-b373-8c54c0da007e', // Ticket UID in above URL
                            'TFA Number here');
}
catch (\PSN\AuthException $e)
{
    print $e->GetError();
    exit;
}
$tokens = $account->GetTokens();

print_r($tokens);

This should authenticate you and provide you with Refresh token and npsso that you can use to authenticate without having to provide credentials.

I store these into a database table, and every time my web app needs to interact with PSN I use those to authenticate.

//****************************************************
// Retrieve refresh and npsso saved to your database 
//****************************************************

$cDB = new mysqli(db_host, db_user, db_passwd, db_name);
$result = $cDB->query('SELECT * from psn_oauth_data"));
$row = $result->fetch_assoc();

$tokens = \PSN\Auth::GrabNewTokens($row['refresh']);
$tokens['npsso'] = $row['npsso'];

//****************************************************
// SAVE new refresh token back to the database
//****************************************************

$sSQL = sprintf('UPDATE psn_oauth_data SET  oauth =  \'%s\', refresh =  \'%s\' WHERE  token_id =1', $tokens['oauth'],  $tokens['refresh']);

$rUpdateResultSet = $cDB->Execute($sSQL);

//****************************************************
// Do you PSN-PHP things using the new Tokens
//****************************************************

$messaging = new \PSN\Messaging($tokens);
.
.
.

This has worked for me.

Hope this helps.

@BonkAssetReader
Copy link

@bozzit appreciate the help i found that bungie link while testing stuff too haha, thanks again.

@BonkAssetReader
Copy link

What about this returning when authenticating, do i need the 2FA code entered in the Auth function? {"error":"invalid_credentials","error_description":"Invalid two step credentials","error_code":4420,"docs":"https://auth.api.sonyentertainmentnetwork.com/docs/","parameters":[]}

@bozzit
Copy link
Contributor

bozzit commented Jan 27, 2018

Well not sure where you got that error from, but ya in my example above to retrieve your oauth tokens you need to supply the 2FA number. Once you have your refresh tokens, you don't need to Authenticate but just refresh them instead.

@wong90
Copy link

wong90 commented Jan 30, 2018

It seems like i was hitting this when i follow this step #54 (comment) :
{"error":"invalid_ticket","error_description":"Invalid ticket","error_code":4421,"docs":"https://auth.api.sonyentertainmentnetwork.com/docs/","parameters":[]}
@bozzit did you hit this error before? Because i already double checked i did pass in the correct ticket_uuid and the 2FA verification code.

@bozzit
Copy link
Contributor

bozzit commented Jan 30, 2018

@wong90 I have not tried this in about 3 weeks, but the above worked for me. I was able to authenticate and gather refresh tokens I've been using ever since.

I would have to try with another PSN account the last thing I would want to do is mess up my oauth refresh tokens and lock myself out.

Sony may have changed things YET again.

@bozzit
Copy link
Contributor

bozzit commented Feb 16, 2018

I have recovered my tokens using this method just now. So it does still work

@mabi86
Copy link

mabi86 commented Mar 22, 2018

@wong90 try this.
when you collect the ticket_uid, before you use the following code:

$account = new \PSN\Auth('yourpsnaccount@yourdomain.com',
                            'yourpsnpassword',
                            '7e7cf194-817d-4001-b373-8c54c0da007e', // Ticket UID
                            'TFA Number here');

you should change params "client_id" in Auth Class file. "client_id" you can get in authenticated 2FA URL. the Auth code change:

private $two_factor_auth_request = array(
        "authentication_type" => "two_step",
        "ticket_uuid" => null,
        "code" => null,
        "client_id" => "78420c74-1fdf-4575-b43f-eb94c7d770bf",  //Replace this value
    );

@krazyjakee
Copy link

krazyjakee commented Mar 28, 2018

I got it to authorize but when I request trophies url I get "Needs to upgrade for PSN access" error. Does the scope need to be updated? Here is my URL:

https://us-tpy.np.community.playstation.net/trophy/v1/trophyTitles/NPWR07466_00/trophyGroups/all/trophies?fields=@default,trophyRare,trophyEarnedRate&npLanguage=en&sortKey=trophyId&iconSize=m

@mgp25
Copy link

mgp25 commented Apr 23, 2018

Hello @bozzit, I am updating my python port (https://github.com/mgp25/psn-api) with the latest PlayStation changes and migrating to HTTP2.

And I have a question for you. While testing all the functions, all worked except sending a message (with the same format this library sends it). PSN has changed the request, but since I'm getting:

b'{"error":{"code":2121729,"message":"Bad request"}}'

I want to ask you if it is still working (at least for messages) with this current library.

Regards

@Tustin
Copy link
Owner

Tustin commented Apr 25, 2018

@mgp25 If you haven't got it working yet, I can take a look at the API again to see what exactly changed.

@mgp25
Copy link

mgp25 commented Apr 25, 2018

@Tustin I haven't yet. The request is the following one (notice that they are using HTTP2 now):

:method: POST
:path: /groupMessaging/v1/messageGroups/~xxxE837DyyyB2E5C.7F6zzz27ED000ECA/messages
:authority: es-gmsg.np.community.playstation.net
:scheme: https
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:59.0) Gecko/20100101 Firefox/59.0
accept: */*
accept-language: es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3
accept-encoding: gzip, deflate, br
content-type: multipart/mixed; boundary="---------------------------26061"
authorization: Bearer 15e000c-36p0-400a-8b53-e94e0009745f
content-length: 204
origin: https://my.playstation.com
dnt: 1


-----------------------------26061
Content-Type: application/json; charset=utf-8
Content-Description: message

{"message":{"messageKind":1,"body":"que tal?"}}
-----------------------------26061--

Since my port is using python, none of the libs were supporting http2, unless hyper. I have opened an issue there python-hyper/hyper#380 (comment) where I asked if I was doing it right:

        boundary = "---------------------------"+str(random.sample(range(10000, 99999), 1)[0])

        header = {
            'origin': 'https://my.playstation.com',
            'Authorization': 'Bearer ' + self.oauth,
            'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:59.0) Gecko/20100101 Firefox/59.0',
            'Content-Type': 'multipart/mixed; boundary='+boundary,
            'accept-encoding': 'gzip, deflate, br',
            'accept': '*/*',
            'dnt': '1',

        }

        message_body = {
            "message": {
                "messageKind": 1,
                "body": message_text
            }
        }

        message = "\r\n"
        message += boundary+"\r\n"
        message += "Content-Type: application/json; charset=utf-8\r\n"
        message += "Content-Description: message\r\n"
        message += "\r\n"
        message += json.dumps(message_body) + "\r\n"
        message += boundary + "--\r\n"


        conn = HTTP20Connection("es-gmsg.np.community.playstation.net:443")
        request = conn.request('POST', "/groupMessaging/v1/messageGroups/"+thread_id+"/messages", headers=header, body=message)
        response = conn.get_response(request)
        print(response.read())

And the response I get from the code above is:

{"error":{"code":2121729,"message":"Bad request"}}

Regards

@mgp25
Copy link

mgp25 commented Jun 11, 2018

Any news @Tustin?

@dollabi11z
Copy link

what a pain in the ass. you have to grab a gdam 2fa code ever time u want a token. we need something that bypasses the dam capcha to make this Automated

@Argosth
Copy link

Argosth commented Aug 1, 2018

Until this month, the API was working fine, now..., I get an empty array from PSN, so I receive the error:

Undefined index: oauth/refresh

I hope someone can help @Tustin finding a solution.

@bozzit
Copy link
Contributor

bozzit commented Aug 1, 2018

I had to manually refresh my token several time in July using the bungie URL in this thread with success. So you should be able to manually get a new token/refresh token.

@Tustin
Copy link
Owner

Tustin commented Aug 1, 2018

@Argosth I made some changes to some headers to match the newest update and everything was working fine for me when I added the update background color + image stuff. So I'm not sure if that issue is because of those header changes, or if you're running an older version of the library that might not work anymore with the old headers. If you haven't, try updating with Composer and see if you notice any difference. If not, I'll need to see some example of what you're trying to do or a more detailed error message so I can try to repro the issue.

Edit: nvm, just realized you posted everything in a different issue 😛. I'll take a look at your code and see if I can figure it out

@Argosth
Copy link

Argosth commented Aug 2, 2018

It works!!!!!!!!!, wow, nice Tustin, it works fine, I just downloaded via composer your new files, and I did not modified any files, even the Auth.php (cause someone said that I have to put mi Client_id into that file, and don't, that gave me an error), so I left all files without any modification, and now it works, thank you Tustin, now I have my trophies updated.

You can visit my personal website: https://www.argosth.com, and can see that I have updated my trophies hehehe, love you Tustin, you are a master.

Thanks, and I hope PSN let us continue with this system without any changes.

@Tustin
Copy link
Owner

Tustin commented Aug 2, 2018

@Argosth glad to hear it fixed the issue! 😄

@Nistelroy78
Copy link

@Argosth Argosth , can you tell me how you got this implented maybe you can help me so i can implented in to my website ( its wordpress ) https://playstationforum.dk

@Argosth
Copy link

Argosth commented Aug 5, 2018

Hey, you just have to download via (composer) the new files in the root of your site, after that, you just have to do what @bozzit commented on Jan 25 above.

@Nistelroy78
Copy link

@Argosth i try that - should this be in the "Index.php" or what .. or where should i put this ? in what file

@Nistelroy78
Copy link

@Argosth
Getting this error in my index.php

Fatal error: Uncaught Error: Class 'PSN\Auth' not found in /var/www/ps4danmark.dk/public_html/moon/psn-php/index.php:4 Stack trace: #0 {main} thrown in /var/www/ps4danmark.dk/public_html/moon/psn-php/index.php on line 4

@Argosth
Copy link

Argosth commented Aug 5, 2018

This is all the proccess I do, it will be enough:

I do everything in a file called (psn.php), is not an index.php.
`
First, the include/require.

<?php
    require "../vendor/tustin/psn-php/vendor/autoload.php";
?>

Next, you should get your Ticket UID, and the password sent to your phone and use the next code.

try {
    $account = new \PSN\Auth('yourpsnemail@mail.com',
                                                'your psn password',
                                                'Your ticke UID code', // Ticket UID in above URL
                                                'Code 2FA sent to your cellphone.');
}
  catch (\PSN\AuthException $e)
{
  print $e->GetError();
  exit;
}

$tokens = $account->GetTokens();
print_r($tokens);

If everything was ok, you will have now the Oauth, Refresh codes, save them in a file.txt or in a database.
Now, an example of use.

$tokens = \PSN\Auth::GrabNewTokens('Your refresh code');
$tokens['npsso'] = 'Your npsso code';
$trophy = new \PSN\Trophy($tokens);
$my_trophies = $trophy->GetMyTrophies();

** Now, you can just do FOR to see every information from the object.**

$totalTitles = count((array)$my_trophies->trophyTitles); // To see the number of games you got.
for ($i = 0; $i < $totalTitles; $i++) {
  echo "Game ID: ".$my_trophies->trophyTitles[$i]->npCommunicationId."<br />";
  echo "Game Title: "$my_trophies->trophyTitles[$i]->trophyTitleName."<br />";
}

Remember to see the documentation in: http://tusticles.com/psn-php/

I hope this information is useful for you.

@Nistelroy78
Copy link

@Argosth

my psn.php file look like this and make error

<?php require "./psn-php/vendor/autoload.php"; try { $account = new \PSN\Auth('testmail@mail', 'password', 'mycode-inside-here', // Ticket UID in above URL 'and-my-code-from-phone'); } catch (\PSN\AuthException $e) { print $e->GetError(); exit; } $tokens = $account->GetTokens(); print_r($tokens); ?>
it gives me this error ( mails etc is change for this qoute -

{"error":"invalid_ticket","error_description":"Invalid ticket","error_code":4421,"docs":"https://auth.api.sonyentertainmentnetwork.com/docs/","parameters":[]}

@Argosth
Copy link

Argosth commented Aug 5, 2018

That error is shown when you try to get a new token information from the same data, you have only 1 attempt to get the oauth, nsspo, refresh etc, so, you go to the URL, get the Ticket UID and the 2FA code, and copy that to your file, and update, and go to your website and look, but not refresh, cause you can execute that only 1 time to see the info.

Try to do it in only one time, if you refresh the website again, you will receive that error.

@Tustin
Copy link
Owner

Tustin commented Sep 19, 2018

The new version of the library now properly supports the 2FA login scheme to get around the Captcha issue. You don't need to store any confidential information like email and password anymore. See here: https://tusticles.com/psn-php/first_login.html

@jbdabes jbdabes closed this as completed May 24, 2019
@GarrettAlbright
Copy link

I got it to authorize but when I request trophies url I get "Needs to upgrade for PSN access" error. Does the scope need to be updated? Here is my URL:

https://us-tpy.np.community.playstation.net/trophy/v1/trophyTitles/NPWR07466_00/trophyGroups/all/trophies?fields=@default,trophyRare,trophyEarnedRate&npLanguage=en&sortKey=trophyId&iconSize=m

@krazyjakee I'm also running into this "Needs to upgrade" brick wall. Were you ever able to figure out a solution?

@Ragowit
Copy link
Collaborator

Ragowit commented Feb 4, 2020

@GarrettAlbright I believe one cause of this can be that you need to accept some new agreement on the account. Have you tried to login with the account you're using on https://my.playstation.com and see if you encounter a new agreement to accept?

@GarrettAlbright
Copy link

@Ragowit This is a brand new account, so it's unlikely that there's some new ToS or something in just the couple days since I created the account. That said, I did try logging in manually to see if there was something else to accept, but the system seems to be down currently - I can't successfully log in regardless of browser or ad blocker status. Will try again later.

In the meantime, my client has hypothesized it's not working because it's not a paid PSN Pro account. Would that make a difference, do you think?

@Ragowit
Copy link
Collaborator

Ragowit commented Feb 5, 2020

@GarrettAlbright I'm not paying for PS+ on my account, so that shouldn't be it.

@GarrettAlbright
Copy link

Okay, I figured it out. For the interest of others in the future, you need to log in at https://account.sonyentertainmentnetwork.com/ (not my.playstation.com), then click "PSN Profile" in the left sidebar. The right part of the page will tell you "You must update your account to continue." Click the "Next" button right below that. Sony will give you a couple more pages of form fields to fill out. After completing this, I'm able to use the library as documented (more or less - the documentation seems out of date. Might submit a PR tomorrow).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests