コード例 #1
0
        public async Task RemoveTokens()
        {
            var user  = fillTestDbHelper.Users.FirstOrDefault();
            var token = await tokensService.CreateTokenPairByUserIdAsync(user.Id);

            var removedToken = await tokensService.RemoveTokensAsync(user.Id, token.AccessToken, new List <long> {
                token.Id.Value
            });

            await Assert.ThrowsAsync <InvalidTokenException>(async() => await tokensService.CheckTokenAsync(token, user.NodeId.Value));
        }
コード例 #2
0
        public async Task <Response> CreateResponseAsync()
        {
            try
            {
                var removedTokens = await tokensService.RemoveTokensAsync(userId, request.AccessToken, request.TokensIds).ConfigureAwait(false);

                var clientConnections = connectionsService.GetUserClientConnections(userId);
                if (clientConnections != null)
                {
                    foreach (var connection in clientConnections)
                    {
                        if (removedTokens.Any(token => token.AccessToken == connection.CurrentToken.AccessToken))
                        {
                            Task closeConnection = new Task(async() =>
                            {
                                try
                                {
                                    if (connection == current)
                                    {
                                        await Task.Delay(4000).ConfigureAwait(false);
                                    }

                                    await connection.ClientSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Connection is closing.", CancellationToken.None).ConfigureAwait(false);
                                }
                                catch (Exception ex)
                                {
                                    Logger.WriteLog(ex);
                                }
                            });
                            closeConnection.Start();
                        }
                    }
                }
                return(new ResultResponse(request.RequestId));
            }
            catch (LogoutException ex)
            {
                Logger.WriteLog(ex, request);
                return(new ResultResponse(request.RequestId, "Invalid access token.", ErrorCode.InvalidAccessToken));
            }
        }