diff --git a/src/Microsoft.Azure.SignalR.AspNet/EndpointProvider/ServiceEndpointProvider.cs b/src/Microsoft.Azure.SignalR.AspNet/EndpointProvider/ServiceEndpointProvider.cs index d59e0fe6b..757aff914 100644 --- a/src/Microsoft.Azure.SignalR.AspNet/EndpointProvider/ServiceEndpointProvider.cs +++ b/src/Microsoft.Azure.SignalR.AspNet/EndpointProvider/ServiceEndpointProvider.cs @@ -55,6 +55,7 @@ public ServiceEndpointProvider(ServiceEndpoint endpoint, ServiceOptions options) public Task GenerateClientAccessTokenAsync(string hubName = null, IEnumerable claims = null, TimeSpan? lifetime = null) { var audience = $"{_audienceBaseUrl}{ClientPath}"; + return _accessKey.GenerateAccessTokenAsync(audience, claims, lifetime ?? _accessTokenLifetime, _algorithm); } diff --git a/src/Microsoft.Azure.SignalR.Common/Auth/LocalTokenProvider.cs b/src/Microsoft.Azure.SignalR.Common/Auth/LocalTokenProvider.cs index 4841f0ce8..cb31715f0 100644 --- a/src/Microsoft.Azure.SignalR.Common/Auth/LocalTokenProvider.cs +++ b/src/Microsoft.Azure.SignalR.Common/Auth/LocalTokenProvider.cs @@ -20,11 +20,12 @@ internal class LocalTokenProvider : IAccessTokenProvider private readonly IEnumerable _claims; - public LocalTokenProvider(AccessKey accessKey, - string audience, - IEnumerable claims, - AccessTokenAlgorithm algorithm = AccessTokenAlgorithm.HS256, - TimeSpan? tokenLifetime = null) + public LocalTokenProvider( + AccessKey accessKey, + string audience, + IEnumerable claims, + AccessTokenAlgorithm algorithm = AccessTokenAlgorithm.HS256, + TimeSpan? tokenLifetime = null) { _accessKey = accessKey ?? throw new ArgumentNullException(nameof(accessKey)); _algorithm = algorithm; diff --git a/src/Microsoft.Azure.SignalR.Common/Auth/MicrosoftEntra/MicrosoftEntraAccessKey.cs b/src/Microsoft.Azure.SignalR.Common/Auth/MicrosoftEntra/MicrosoftEntraAccessKey.cs index e6291c009..acd3d4490 100644 --- a/src/Microsoft.Azure.SignalR.Common/Auth/MicrosoftEntra/MicrosoftEntraAccessKey.cs +++ b/src/Microsoft.Azure.SignalR.Common/Auth/MicrosoftEntra/MicrosoftEntraAccessKey.cs @@ -121,7 +121,7 @@ public async Task GenerateAccessTokenAsync(string audience, AccessTokenAlgorithm algorithm, CancellationToken ctoken = default) { - if (!_initializedTcs.Task.IsCompleted || NeedRefresh) + if (!Initialized || NeedRefresh) { var source = new CancellationTokenSource(Constants.Periods.DefaultUpdateAccessKeyTimeout); _ = UpdateAccessKeyAsync(source.Token);