Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/Microsoft.Azure.SignalR.Management.net8.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions api/Microsoft.Azure.SignalR.Management.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -53,7 +53,7 @@ public async Task<NegotiationResponse> 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);
Expand All @@ -69,4 +69,4 @@ public async Task<NegotiationResponse> NegotiateAsync(string hubName, Negotiatio
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 <see cref="TokenLifetime"/>. By default it is false.
/// </summary>
public bool CloseOnAuthenticationExpiration { get; set; }
}

/// <summary>
/// Gets or sets a bitmask combining one or more <see cref="HttpTransportType"/> values that specify what transports the server should use to receive HTTP requests.
/// </summary>
public HttpTransportType? Transports { get; set; }
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<ServiceManagerOptions>(o =>
{
o.ServiceEndpoints = endpoints;
o.ServiceTransportType = serviceTransportType;
}).BuildServiceProvider();
var negotiateProcessor = provider.GetRequiredService<NegotiateProcessor>();
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()
{
Expand All @@ -141,4 +166,4 @@ internal async Task GenerateClientEndpointTestWithClientEndpoint()
var negotiationResponse = (await negotiateProcessor.NegotiateAsync(HubName, null)).Url;
Assert.Equal("https://remote/client/?hub=signalrbench", negotiationResponse);
}
}
}
Loading