public async Task <NegotiationResponse> NegotiateAsync(string hubName, NegotiationOptions negotiationOptions, CancellationToken cancellationToken = default) { negotiationOptions ??= NegotiationOptions.Default; var httpContext = negotiationOptions.HttpContext; var userId = negotiationOptions.UserId; var claims = negotiationOptions.Claims; var isDiagnosticClient = negotiationOptions.IsDiagnosticClient; var enableDetailedErrors = negotiationOptions.EnableDetailedErrors; var lifetime = negotiationOptions.TokenLifetime; try { if (cancellationToken == default && httpContext != null) { cancellationToken = httpContext.RequestAborted; } var candidateEndpoints = _serviceEndpointManager.GetEndpoints(hubName); var selectedEndpoint = _router.GetNegotiateEndpoint(httpContext, candidateEndpoints); var provider = _serviceEndpointManager.GetEndpointProvider(selectedEndpoint); Func <IEnumerable <Claim> > claimProvider = null; if (claims != null) { claimProvider = () => claims; } var claimsWithUserId = ClaimsUtility.BuildJwtClaims(httpContext?.User, userId: userId, claimProvider, enableDetailedErrors: enableDetailedErrors, isDiagnosticClient: isDiagnosticClient); var tokenTask = provider.GenerateClientAccessTokenAsync(hubName, claimsWithUserId, lifetime); await tokenTask.OrTimeout(cancellationToken, Timeout, GeneratingTokenTaskDescription); return(new NegotiationResponse { Url = provider.GetClientEndpoint(hubName, null, null), AccessToken = tokenTask.Result }); } catch (Exception e) when(e is OperationCanceledException || e is TimeoutException) { throw new AzureSignalRException(ErrorMsg, e); } }
public override ValueTask <NegotiationResponse> NegotiateAsync(NegotiationOptions negotiationOptions = null, CancellationToken cancellationToken = default) => _baseHubContext.NegotiateAsync(negotiationOptions, cancellationToken);
public override Task <NegotiationResponse> NegotiateAsync(NegotiationOptions options, CancellationToken cancellationToken) { return(_negotiateProcessor.NegotiateAsync(_hubName, options, cancellationToken)); }
/// <summary> /// Performs a negotiation operation asynchronously that routes a client to a Azure SignalR instance. /// </summary> /// <returns>A negotiation response object that contains an endpoint url and an access token for the client to connect to the Azure SignalR instance. </returns> public abstract ValueTask <NegotiationResponse> NegotiateAsync(NegotiationOptions negotiationOptions = null, CancellationToken cancellationToken = default);
/// <summary> /// Performs a negotiation operation asynchronously that routes a client to a Azure SignalR instance. /// </summary> /// <returns>A negotiation response object that contains an endpoint url and an access token for the client to connect to the Azure SignalR instance. </returns> public virtual Task <NegotiationResponse> NegotiateAsync(NegotiationOptions negotiationOptions = null, CancellationToken cancellationToken = default) => throw new NotImplementedException();
/// <summary> /// Performs a negotiation operation asynchronously that routes a client to a Azure SignalR instance. /// </summary> /// <returns>A negotiation response object that contains an endpoint url and an access token for the client to connect to the Azure SignalR instance. </returns> public virtual Task <NegotiationResponse> NegotiateAsync(NegotiationOptions negotiationOptions = null, CancellationToken cancellationToken = default) => null;