src/Client.php
public function login(string $ticketUuidOrRefreshToken, string $code = null) 
    {
        if ($code === null) {
            $response = $this->httpClient()->post(self::AUTH_API . 'oauth/token', [
                "app_context" => "inapp_ios",
                "client_id" => self::CLIENT_ID,
                "client_secret" => self::CLIENT_SECRET,
                "refresh_token" => $ticketUuidOrRefreshToken,
                "duid" => self::DUID,
                "grant_type" => "refresh_token",
                "scope" => self::SCOPE
            ]);
        } else {
            $response = $this->httpClient()->post(self::AUTH_API . 'ssocookie', [
                'authentication_type' => 'two_step',
                'ticket_uuid' => $ticketUuidOrRefreshToken,
                'code' => $code,
                'client_id' => self::CLIENT_ID
            ]);

            $npsso = $response->npsso;

            $response = $this->httpClient()->get(self::AUTH_API . 'oauth/authorize', [
                'duid' => self::DUID,
                'client_id' => self::CLIENT_ID,
                'response_type' => 'code',
                'scope' => self::SCOPE,
                'redirect_uri' => 'com.playstation.PlayStationApp://redirect'
            ], [
                'Cookie' => 'npsso=' . $npsso
            ]);

            if (($response instanceof Response) === false) {
                throw new \Exception('Unexpected response');
            }

            $grant = $response->getHeaderLine('X-NP-GRANT-CODE');

            if (empty($grant)) {
                throw new \Exception('Unable to get X-NP-GRANT-CODE');
            }

            $response = $this->httpClient()->post(self::AUTH_API . 'oauth/token', [
                'client_id' => self::CLIENT_ID,
                'client_secret' => self::CLIENT_SECRET,
                'duid' => self::DUID,
                'scope' => self::SCOPE,
                'redirect_uri' => 'com.playstation.PlayStationApp://redirect',
                'code' => $grant,
                'grant_type' => 'authorization_code'
            ]);

        }

        $this->accessToken = $response->access_token;
        $this->refreshToken = $response->refresh_token;
        $this->expiresIn = $response->expires_in;

        $handler = \GuzzleHttp\HandlerStack::create();
        $handler->push(Middleware::mapRequest(new TokenMiddleware($this->accessToken(), $this->refreshToken(), $this->expireDate())));

        $newOptions = array_merge(['handler' => $handler], $this->options);
    
        $this->httpClient = new HttpClient(new \GuzzleHttp\Client($newOptions));
    }
public function login(string $ticketUuidOrRefreshToken, string $code = null) 
    {
        if ($code === null) {
            $response = $this->httpClient()->post(self::AUTH_API . 'oauth/token', [
                "app_context" => "inapp_ios",
                "client_id" => self::CLIENT_ID,
                "client_secret" => self::CLIENT_SECRET,
                "refresh_token" => $ticketUuidOrRefreshToken,
                "duid" => self::DUID,
                "grant_type" => "refresh_token",
                "scope" => self::SCOPE
            ]);
        } else {
            $response = $this->httpClient()->post(self::AUTH_API . 'ssocookie', [
                'authentication_type' => 'two_step',
                'ticket_uuid' => $ticketUuidOrRefreshToken,
                'code' => $code,
                'client_id' => self::CLIENT_ID
            ]);

            $npsso = $response->npsso;

            $response = $this->httpClient()->get(self::AUTH_API . 'oauth/authorize', [
                'duid' => self::DUID,
                'client_id' => self::CLIENT_ID,
                'response_type' => 'code',
                'scope' => self::SCOPE,
                'redirect_uri' => 'com.playstation.PlayStationApp://redirect'
            ], [
                'Cookie' => 'npsso=' . $npsso
            ]);

            if (($response instanceof Response) === false) {
                throw new \Exception('Unexpected response');
            }

            $grant = $response->getHeaderLine('X-NP-GRANT-CODE');

            if (empty($grant)) {
                throw new \Exception('Unable to get X-NP-GRANT-CODE');
            }

            $response = $this->httpClient()->post(self::AUTH_API . 'oauth/token', [
                'client_id' => self::CLIENT_ID,
                'client_secret' => self::CLIENT_SECRET,
                'duid' => self::DUID,
                'scope' => self::SCOPE,
                'redirect_uri' => 'com.playstation.PlayStationApp://redirect',
                'code' => $grant,
                'grant_type' => 'authorization_code'
            ]);

        }

        $this->accessToken = $response->access_token;
        $this->refreshToken = $response->refresh_token;
        $this->expiresIn = $response->expires_in;

        $handler = \GuzzleHttp\HandlerStack::create();
        $handler->push(Middleware::mapRequest(new TokenMiddleware($this->accessToken(), $this->refreshToken(), $this->expireDate())));

        $newOptions = array_merge(['handler' => $handler], $this->options);
    
        $this->httpClient = new HttpClient(new \GuzzleHttp\Client($newOptions));
    }
public function login ( string $ ticketUuidOrRefreshToken , string $ code = null ) { if ( $ code === null ) { $ response = $ this -> httpClient ( ) -> post ( self :: AUTH_API . 'oauth/token' , [ "app_context" => "inapp_ios" , "client_id" => self :: CLIENT_ID , "client_secret" => self :: CLIENT_SECRET , "refresh_token" => $ ticketUuidOrRefreshToken , "duid" => self :: DUID , "grant_type" => "refresh_token" , "scope" => self :: SCOPE ] ) ; } else { $ response = $ this -> httpClient ( ) -> post ( self :: AUTH_API . 'ssocookie' , [ 'authentication_type' => 'two_step' , 'ticket_uuid' => $ ticketUuidOrRefreshToken , 'code' => $ code , 'client_id' => self :: CLIENT_ID ] ) ; $ npsso = $ response -> npsso ; $ response = $ this -> httpClient ( ) -> get ( self :: AUTH_API . 'oauth/authorize' , [ 'duid' => self :: DUID , 'client_id' => self :: CLIENT_ID , 'response_type' => 'code' , 'scope' => self :: SCOPE , 'redirect_uri' => 'com.playstation.PlayStationApp://redirect' ] , [ 'Cookie' => 'npsso=' . $ npsso ] ) ; if ( ( $ response instanceof Response ) === false ) { throw new \ Exception ( 'Unexpected response' ) ; } $ grant = $ response -> getHeaderLine ( 'X-NP-GRANT-CODE' ) ; if ( empty ( $ grant ) ) { throw new \ Exception ( 'Unable to get X-NP-GRANT-CODE' ) ; } $ response = $ this -> httpClient ( ) -> post ( self :: AUTH_API . 'oauth/token' , [ 'client_id' => self :: CLIENT_ID , 'client_secret' => self :: CLIENT_SECRET , 'duid' => self :: DUID , 'scope' => self :: SCOPE , 'redirect_uri' => 'com.playstation.PlayStationApp://redirect' , 'code' => $ grant , 'grant_type' => 'authorization_code' ] ) ; } $ this -> accessToken = $ response -> access_token ; $ this -> refreshToken = $ response -> refresh_token ; $ this -> expiresIn = $ response -> expires_in ; $ handler = \ GuzzleHttp \ HandlerStack :: create ( ) ; $ handler -> push ( Middleware :: mapRequest ( new TokenMiddleware ( $ this -> accessToken ( ) , $ this -> refreshToken ( ) , $ this -> expireDate ( ) ) ) ) ; $ newOptions = array_merge ( [ 'handler' => $ handler ] , $ this -> options ) ; $ this -> httpClient = new HttpClient ( new \ GuzzleHttp \ Client ( $ newOptions ) ) ; }
Login to PlayStation network using a refresh token or 2FA.

@param string $ticketUuidOrRefreshToken Ticket UUID for 2FA, or the refresh token.
@param string $code 2FA code sent to your device (ignore if using refresh token).
@return void
Login to PlayStation network using a refresh token or 2FA .