Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 18a9037

Browse files
committed
* 'master' of https://github.com/tlaverdure/Laravel-Echo-Server: Allow wildcard and multi domain authHost option Update private-channel.ts
2 parents a2b51fc + 8a2ff3a commit 18a9037

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/channels/private-channel.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var request = require('request');
22
import { Channel } from './channel';
33
import { Log } from './../log';
4+
var url = require('url');
45

56
export class PrivateChannel {
67
/**
@@ -26,7 +27,7 @@ export class PrivateChannel {
2627
*/
2728
authenticate(socket: any, data: any): Promise<any> {
2829
let options = {
29-
url: this.authHost() + this.options.authEndpoint,
30+
url: this.authHost(socket) + this.options.authEndpoint,
3031
form: { channel_name: data.channel },
3132
headers: (data.auth && data.auth.headers) ? data.auth.headers : {},
3233
rejectUnauthorized: false
@@ -40,9 +41,26 @@ export class PrivateChannel {
4041
*
4142
* @return {string}
4243
*/
43-
protected authHost(): string {
44-
return (this.options.authHost) ?
44+
protected authHost(socket: any): string {
45+
let referer: Object = url.parse(socket.request.headers.referer);
46+
let authHostSelected: string = 'http://localhost';
47+
let authHosts: any = (this.options.authHost) ?
4548
this.options.authHost : this.options.host;
49+
50+
if(typeof authHosts === "string")
51+
authHosts = [authHosts];
52+
53+
for(let authHost of authHosts)
54+
{
55+
authHostSelected = authHost;
56+
if(referer.hostname.substr(referer.hostname.indexOf('.')) === authHostSelected || referer.protocol + "//" + referer.host === authHostSelected || referer.host === authHostSelected)
57+
{
58+
authHostSelected = referer.protocol+"//"+referer.host;
59+
break;
60+
}
61+
}
62+
63+
return authHostSelected;
4664
}
4765

4866
/**

0 commit comments

Comments
 (0)