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

[5.3] json_decodes Pusher message from validAuthentiactoinResponse #15262

Merged
merged 3 commits into from
Sep 5, 2016

Conversation

eahrold
Copy link

@eahrold eahrold commented Sep 3, 2016

Addresses the (probably misplaced) issue laravel/echo#34.

Pusher by default encodes it's response as a string

    /**
     * Creates a socket signature.
     *
     * @param string $socket_id
     * @param string $custom_data
     *
     * @return string
     */
    public function socket_auth($channel, $socket_id, $custom_data = null)
    {
        $this->validate_channel($channel);
        $this->validate_socket_id($socket_id);

        if ($custom_data) {
            $signature = hash_hmac('sha256', $socket_id.':'.$channel.':'.$custom_data, $this->settings['secret'], false);
        } else {
            $signature = hash_hmac('sha256', $socket_id.':'.$channel, $this->settings['secret'], false);
        }

        $signature = array('auth' => $this->settings['auth_key'].':'.$signature);
        // add the custom data if it has been supplied
        if ($custom_data) {
            $signature['channel_data'] = $custom_data;
        }

        return json_encode($signature);
    }

Which in situations as described in the open issue, led to an incorrect response.

@@ -88,4 +91,14 @@ public function getPusher()
{
return $this->pusher;
}

/**
* Decoded PusherResponse.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GrahamCampbell thanks.

@GrahamCampbell GrahamCampbell changed the title json_decodes Pusher message from validAuthentiactoinResponse [5.3] json_decodes Pusher message from validAuthentiactoinResponse Sep 4, 2016
@@ -56,10 +56,13 @@ public function auth($request)
public function validAuthenticationResponse($request, $result)
{
if (Str::startsWith($request->channel_name, 'private')) {
return $this->pusher->socket_auth($request->channel_name, $request->socket_id);
return $this->decodedPusherRepsone(
$this->pusher->socket_auth($request->channel_name, $request->socket_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misspelled Response.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BrandonSurowiec thanks. Fixed in 487e985.

@taylorotwell
Copy link
Member

I need to know exactly what is broken and what this is fixing.

@eahrold
Copy link
Author

eahrold commented Sep 5, 2016

@taylorotwell Absolutely.
I reported the symptom here laravel/echo#34.
And while it's not universally broken, there are conditions that cause it to break.

For example, when using the PusherBroadcaster the response from the Broadcast::auth() route is returning a string. With a package like Barryvdh\Debugbar, when executing it's modifyResponse, determines it's a rendered response and injects itself onto the string. The new string is no longer correctly parsed on the front end.

This PR simply casts the pusher response so it's correctly typed as it moves up the chain.

Thanks.

@taylorotwell taylorotwell merged commit 487e985 into laravel:5.3 Sep 5, 2016
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

Successfully merging this pull request may close these issues.

None yet

4 participants