Esempio n. 1
0
        public NegotiationResponse Process(HttpContext context, string hubName)
        {
            var claims       = BuildClaims(context);
            var request      = context.Request;
            var originalPath = GetOriginalPath(request.Path);
            var provider     = _endpointManager.GetEndpointProvider(_router.GetNegotiateEndpoint(context, _endpointManager.GetEndpoints(hubName)));

            if (provider == null)
            {
                return(null);
            }

            var clientRequestId = _connectionRequestIdProvider.GetRequestId();

            var queryString = GetQueryString(_connectionRequestIdProvider, request.QueryString.HasValue ? request.QueryString.Value.Substring(1) : null);

            return(new NegotiationResponse
            {
                Url = provider.GetClientEndpoint(hubName, originalPath, queryString),
                AccessToken = provider.GenerateClientAccessToken(hubName, claims, requestId: clientRequestId),
                // Need to set this even though it's technically protocol violation https://github.com/aspnet/SignalR/issues/2133
                AvailableTransports = new List <AvailableTransport>()
            });
        }
Esempio n. 2
0
        private string GetQueryString(string originalQueryString)
        {
            var clientRequestId = _connectionRequestIdProvider.GetRequestId();

            if (clientRequestId != null)
            {
                clientRequestId = WebUtility.UrlEncode(clientRequestId);
            }
            if (originalQueryString != null)
            {
                return($"{originalQueryString}&{Constants.QueryParameter.ConnectionRequestId}={clientRequestId}");
            }

            return($"{Constants.QueryParameter.ConnectionRequestId}={clientRequestId}");
        }
Esempio n. 3
0
        private string GetQueryString(string originalQueryString, string cultureName)
        {
            var clientRequestId = _connectionRequestIdProvider.GetRequestId();

            if (clientRequestId != null)
            {
                clientRequestId = WebUtility.UrlEncode(clientRequestId);
            }

            var queryString = $"{Constants.QueryParameter.ConnectionRequestId}={clientRequestId}";

            if (!string.IsNullOrEmpty(cultureName))
            {
                queryString += $"&{Constants.QueryParameter.RequestCulture}={cultureName}";
            }

            return(originalQueryString != null
                ? $"{originalQueryString}&{queryString}"
                : queryString);
        }