diff --git a/api/Microsoft.Azure.SignalR.Management.net8.0.cs b/api/Microsoft.Azure.SignalR.Management.net8.0.cs index 55058ac80..e7722b23a 100644 --- a/api/Microsoft.Azure.SignalR.Management.net8.0.cs +++ b/api/Microsoft.Azure.SignalR.Management.net8.0.cs @@ -60,6 +60,7 @@ public NegotiationOptions() { } public Microsoft.AspNetCore.Http.HttpContext HttpContext { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public bool IsDiagnosticClient { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public System.TimeSpan TokenLifetime { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public Microsoft.AspNetCore.Http.Connections.HttpTransportType? Transports { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public string UserId { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } } public partial class NewtonsoftServiceHubProtocolOptions diff --git a/api/Microsoft.Azure.SignalR.Management.netstandard2.0.cs b/api/Microsoft.Azure.SignalR.Management.netstandard2.0.cs index e01b777ed..3e1a7bd96 100644 --- a/api/Microsoft.Azure.SignalR.Management.netstandard2.0.cs +++ b/api/Microsoft.Azure.SignalR.Management.netstandard2.0.cs @@ -60,6 +60,7 @@ public NegotiationOptions() { } public Microsoft.AspNetCore.Http.HttpContext HttpContext { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public bool IsDiagnosticClient { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public System.TimeSpan TokenLifetime { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public Microsoft.AspNetCore.Http.Connections.HttpTransportType? Transports { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public string UserId { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } } public partial class NewtonsoftServiceHubProtocolOptions diff --git a/src/Microsoft.Azure.SignalR.Management/Negotiation/NegotiateProcessor.cs b/src/Microsoft.Azure.SignalR.Management/Negotiation/NegotiateProcessor.cs index afbc56913..5763a6774 100644 --- a/src/Microsoft.Azure.SignalR.Management/Negotiation/NegotiateProcessor.cs +++ b/src/Microsoft.Azure.SignalR.Management/Negotiation/NegotiateProcessor.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft. All rights reserved. +// Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; @@ -53,7 +53,7 @@ public async Task NegotiateAsync(string hubName, Negotiatio } var closeOnAuthenticationExpiration = negotiationOptions.CloseOnAuthenticationExpiration; var authenticationExpiresOn = closeOnAuthenticationExpiration ? DateTimeOffset.UtcNow.Add(negotiationOptions.TokenLifetime) : default(DateTimeOffset?); - var claimsWithUserId = ClaimsUtility.BuildJwtClaims(httpContext?.User, userId: userId, claimProvider, enableDetailedErrors: enableDetailedErrors, isDiagnosticClient: isDiagnosticClient, closeOnAuthenticationExpiration: closeOnAuthenticationExpiration, authenticationExpiresOn: authenticationExpiresOn); + var claimsWithUserId = ClaimsUtility.BuildJwtClaims(httpContext?.User, userId: userId, claimProvider, enableDetailedErrors: enableDetailedErrors, isDiagnosticClient: isDiagnosticClient, closeOnAuthenticationExpiration: closeOnAuthenticationExpiration, authenticationExpiresOn: authenticationExpiresOn, httpTransportType: negotiationOptions.Transports); var tokenTask = provider.GenerateClientAccessTokenAsync(hubName, claimsWithUserId, lifetime); await tokenTask.OrTimeout(cancellationToken, Timeout, GeneratingTokenTaskDescription); @@ -69,4 +69,4 @@ public async Task NegotiateAsync(string hubName, Negotiatio } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Azure.SignalR.Management/Negotiation/NegotiationOptions.cs b/src/Microsoft.Azure.SignalR.Management/Negotiation/NegotiationOptions.cs index f78e50cbb..4fcf0c30a 100644 --- a/src/Microsoft.Azure.SignalR.Management/Negotiation/NegotiationOptions.cs +++ b/src/Microsoft.Azure.SignalR.Management/Negotiation/NegotiationOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft. All rights reserved. +// Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; @@ -48,4 +48,9 @@ public class NegotiationOptions /// Gets or sets the flag indicates that whether the connection should be closed when the authentication token expires. The lifetime of the token is determined by . By default it is false. /// public bool CloseOnAuthenticationExpiration { get; set; } -} \ No newline at end of file + + /// + /// Gets or sets a bitmask combining one or more values that specify what transports the server should use to receive HTTP requests. + /// + public HttpTransportType? Transports { get; set; } +} diff --git a/test/Microsoft.Azure.SignalR.Management.Tests/NegotiateProcessorFacts.cs b/test/Microsoft.Azure.SignalR.Management.Tests/NegotiateProcessorFacts.cs index 5e313374a..b78e753a2 100644 --- a/test/Microsoft.Azure.SignalR.Management.Tests/NegotiateProcessorFacts.cs +++ b/test/Microsoft.Azure.SignalR.Management.Tests/NegotiateProcessorFacts.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft. All rights reserved. +// Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; @@ -128,6 +128,31 @@ public async Task GetDiagnosticClientNegotiateResponseTest(bool isDiagnosticClie (!hasClaims && !token.Claims.Any(c => c.Type == "a"))); } + [Theory] + [InlineData(ServiceTransportType.Persistent)] + [InlineData(ServiceTransportType.Transient)] + public async Task NegotiateWithHttpTransportType(ServiceTransportType serviceTransportType) + { + var endpoints = FakeEndpointUtils.GetFakeEndpoint(1).ToArray(); + var provider = new ServiceCollection().AddSignalRServiceManager() + .Configure(o => + { + o.ServiceEndpoints = endpoints; + o.ServiceTransportType = serviceTransportType; + }).BuildServiceProvider(); + var negotiateProcessor = provider.GetRequiredService(); + var negotiationResponse = await negotiateProcessor.NegotiateAsync( + HubName, + new NegotiationOptions + { + Transports = AspNetCore.Http.Connections.HttpTransportType.LongPolling | AspNetCore.Http.Connections.HttpTransportType.ServerSentEvents + }); + var tokenString = negotiationResponse.AccessToken; + var handler = new JwtSecurityTokenHandler(); + var token = handler.ReadJwtToken(tokenString); + Assert.Equal("6", token.Claims.Single(c => c.Type == Constants.ClaimType.HttpTransportType).Value); + } + [Fact] internal async Task GenerateClientEndpointTestWithClientEndpoint() { @@ -141,4 +166,4 @@ internal async Task GenerateClientEndpointTestWithClientEndpoint() var negotiationResponse = (await negotiateProcessor.NegotiateAsync(HubName, null)).Url; Assert.Equal("https://remote/client/?hub=signalrbench", negotiationResponse); } -} \ No newline at end of file +}