diff --git a/src/core/auth/channel_authorizer.ts b/src/core/auth/channel_authorizer.ts index 20907948b..f4994545b 100644 --- a/src/core/auth/channel_authorizer.ts +++ b/src/core/auth/channel_authorizer.ts @@ -24,6 +24,17 @@ const composeChannelQuery = ( encodeURIComponent(authOptions.params[i]); } + if (authOptions.paramProvider != null) { + let dynamicParams = authOptions.paramProvider(); + for (var i in dynamicParams) { + query += + '&' + + encodeURIComponent(i) + + '=' + + encodeURIComponent(dynamicParams[i]); + } + } + return query; }; diff --git a/src/core/auth/options.ts b/src/core/auth/options.ts index 518743468..b495cf4d1 100644 --- a/src/core/auth/options.ts +++ b/src/core/auth/options.ts @@ -56,6 +56,8 @@ export interface AuthOptionsT { endpoint: string; params?: any; headers?: any; + paramProvider?: () => any; + headerProvider?: () => any; customHandler?: AuthHandler; } @@ -71,4 +73,6 @@ export interface InternalAuthOptions { endpoint: string; params?: any; headers?: any; + paramProvider?: () => any; + headerProvider?: () => any; } diff --git a/src/core/auth/user_authenticator.ts b/src/core/auth/user_authenticator.ts index e39bc8f93..4547d9474 100644 --- a/src/core/auth/user_authenticator.ts +++ b/src/core/auth/user_authenticator.ts @@ -22,6 +22,17 @@ const composeChannelQuery = ( encodeURIComponent(authOptions.params[i]); } + if (authOptions.paramProvider != null) { + let dynamicParams = authOptions.paramProvider(); + for (var i in dynamicParams) { + query += + '&' + + encodeURIComponent(i) + + '=' + + encodeURIComponent(dynamicParams[i]); + } + } + return query; }; diff --git a/src/runtimes/isomorphic/auth/xhr_auth.ts b/src/runtimes/isomorphic/auth/xhr_auth.ts index 0ff386b0b..80a437903 100644 --- a/src/runtimes/isomorphic/auth/xhr_auth.ts +++ b/src/runtimes/isomorphic/auth/xhr_auth.ts @@ -27,6 +27,12 @@ const ajax: AuthTransport = function( for (var headerName in authOptions.headers) { xhr.setRequestHeader(headerName, authOptions.headers[headerName]); } + if (authOptions.headerProvider != null) { + let dynamicHeaders = authOptions.headerProvider(); + for (var headerName in dynamicHeaders) { + xhr.setRequestHeader(headerName, dynamicHeaders[headerName]); + } + } xhr.onreadystatechange = function() { if (xhr.readyState === 4) { @@ -60,7 +66,7 @@ const ajax: AuthTransport = function( suffix = UrlStore.buildLogSuffix('authenticationEndpoint'); break; case AuthRequestType.ChannelAuthorization: - suffix = `Clients must be authenticated to join private or presence channels. ${UrlStore.buildLogSuffix( + suffix = `Clients must be authorized to join private or presence channels. ${UrlStore.buildLogSuffix( 'authorizationEndpoint' )}`; break; diff --git a/src/runtimes/web/dom/sockjs b/src/runtimes/web/dom/sockjs index 5b91dbc0e..bdec828fe 160000 --- a/src/runtimes/web/dom/sockjs +++ b/src/runtimes/web/dom/sockjs @@ -1 +1 @@ -Subproject commit 5b91dbc0e217a9cd959f915fec090370b29878da +Subproject commit bdec828fe39827c6df5801244246193aae5b0b11 diff --git a/types/src/core/auth/options.d.ts b/types/src/core/auth/options.d.ts index 3e9c103dc..56482e218 100644 --- a/types/src/core/auth/options.d.ts +++ b/types/src/core/auth/options.d.ts @@ -32,6 +32,8 @@ export interface AuthOptionsT { endpoint: string; params?: any; headers?: any; + paramProvider?: () => any; + headerProvider?: () => any; customHandler?: AuthHandler; } export declare type UserAuthenticationOptions = AuthOptionsT; @@ -41,4 +43,6 @@ export interface InternalAuthOptions { endpoint: string; params?: any; headers?: any; + paramProvider?: () => any; + headerProvider?: () => any; }