1
1
var request = require ( 'request' ) ;
2
2
import { Channel } from './channel' ;
3
3
import { Log } from './../log' ;
4
+ var url = require ( 'url' ) ;
4
5
5
6
export class PrivateChannel {
6
7
/**
@@ -26,7 +27,7 @@ export class PrivateChannel {
26
27
*/
27
28
authenticate ( socket : any , data : any ) : Promise < any > {
28
29
let options = {
29
- url : this . authHost ( ) + this . options . authEndpoint ,
30
+ url : this . authHost ( socket ) + this . options . authEndpoint ,
30
31
form : { channel_name : data . channel } ,
31
32
headers : ( data . auth && data . auth . headers ) ? data . auth . headers : { } ,
32
33
rejectUnauthorized : false
@@ -40,9 +41,26 @@ export class PrivateChannel {
40
41
*
41
42
* @return {string }
42
43
*/
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 ) ?
45
48
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 ;
46
64
}
47
65
48
66
/**
0 commit comments