1

嗨,伙计们,

我在订阅私人推送频道时收到以下错误消息:

Invalid signature: Expected HMAC SHA256 hex digest of 124425.1545539:private-dash-98, but got e7ed825903c1e18931cceebba457270a6b1e79331387527ab97e430ba4d22068

按钮控制台

Pusher : State changed : initialized -> connecting
Pusher : Connecting : {"transport":"xhr_streaming","url":"https://sockjs-
eu.pusher.com:443/pusher/app/XXXXXX?
protocol=7&client=js&version=4.2.2"}
Pusher : State changed : connecting -> connected ID 124425.1545539
Pusher : Event sent : {"event":"pusher:subscribe","data":
{"auth":"e24378fc4fcd43c36aa3:
e7ed825903c1e18931cceebba457270a6b1e79331387527ab97e430ba4d22068"
,"channel":"private-dash-98"}}
Pusher : Event recd : {"event":"pusher:error","data":
{"code":null,"message":"Invalid signature: Expected HMAC SHA256 hex digest 
of 124425.1545539:private-dash-98, but got 
e7ed825903c1e18931cceebba457270a6b1e79331387527ab97e430ba4d22068"}}
Pusher : Error : {"type":"WebSocketError","error":
{"type":"PusherError","data":{"code":null,"message":"Invalid signature: 
Expected HMAC SHA256 hex digest of 124425.1545539:private-dash-98, but got 
e7ed825903c1e18931cceebba457270a6b1e79331387527ab97e430ba4d22068"}}}

客户: Angular 5 和pusher-library(版本 4.2.2)

Pusher.logToConsole = true;

        this.pusher = new Pusher(environment.pusherAppKey, {
            cluster: 'eu',
            encrypted: true,
            authEndpoint: environment.api + environment.pusherAuthUrl + '?areaId=' + this.locationService.selectedAreaId,
            auth: {
                headers: {
                    'Authorization': 'Bearer ' + this.authService.getAccessToken()
                }
            }
        });

        this.channel = this.pusher.subscribe('private-dash-98');

后端:带有pusher-library 的AspNet Core 2.0 Web Api

    var authToken = pusher.Auth("private-dash-98", "124425.1545539");

    public string Auth(string channelName, string socketId)
    {
        var auth = _pusher.Authenticate(channelName, socketId);
        return auth.ToJson();
    }

Pusher auth-endpoint 返回以下内容:

{"auth":"e24378fc4fcd43c36aa3:e7ed825903c1e18931cceebba457270a6b1e79331387527ab97e430ba4d22068"}

端点结果似乎完全正确。有没有格式问题?

有什么建议么?谢谢!

4

1 回答 1

0

我解决了我的问题。我错过了我的 api 控制器中的socket_id :

    [HttpPost("auth")]
    public async Task<IActionResult> GetAuthToken([FromQuery] int? areaId, [FromForm] string socket_id)
    {
        try
        {
            var pusher = new PusherManager(_appSettings);
            var authToken = pusher.Auth("private-area-" + areaId, socket_id);

            return Ok(authToken);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex.ToString());
            return new StatusCodeResult(500);
        }
    }

上面的代码现在可以按预期工作。

于 2018-02-05T08:22:46.763 回答