Esempio n. 1
0
    public async ValueTask HandleAsync(ConnectedClient sender, Authenticate message, CancellationToken cancellationToken)
    {
        var authenticationResult = await _tokenAuthenticationService.AuthenticateAsync(message.AccessToken, cancellationToken)
                                   .ConfigureAwait(false);

        _connectedClientContext.SetAuthenticatedContext(authenticationResult.ClaimsPrincipal, authenticationResult.JwtSecurityToken);
    }
Esempio n. 2
0
    public async ValueTask <ConnectedClient> ConnectAsync(IConnection connection, CancellationToken cancellationToken)
    {
        if (!(await connection.ReceiveAsync(cancellationToken).ConfigureAwait(false) is Authenticate authenticate))
        {
            await connection.SendAsync(new Disconnected("First message is not a valid Authenticate message."), cancellationToken).ConfigureAwait(false);

            throw new InvalidOperationException("First message is not a valid Authenticate message.");
        }

        var authenticationResult = await _tokenAuthenticationService.AuthenticateAsync(authenticate.AccessToken, cancellationToken)
                                   .ConfigureAwait(false);

        _connectedClientContext.SetAuthenticatedContext(authenticationResult.ClaimsPrincipal, authenticationResult.JwtSecurityToken);

        var connectedClient = await _connectionInitializer.ConnectAsync(connection, cancellationToken)
                              .ConfigureAwait(false);

        _connectedClientContext.SetConnectedClient(connectedClient);

        return(connectedClient);
    }