public async Task InitializeAsync(string token)
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                await DisconnectAsync();
            }
            try
            {
                var payload = _jwtHandler.GetTokenPayload(token);
                if (payload is null)
                {
                    await DisconnectAsync();

                    return;
                }

                var group = Guid.Parse(payload.Subject).ToUserGroup();
                await Groups.AddToGroupAsync(Context.ConnectionId, group);
                await ConnectAsync();
            }
            catch
            {
                await DisconnectAsync();
            }
        }
Exemple #2
0
        public (bool, JsonWebTokenPayload) IsActiveAsync(string token)
        {
            var result = _jwtHandler.GetTokenPayload(token);

            if (result is null)
            {
                return(false, null);
            }
            return(true, result);
        }
        public async Task InitiliazeAsync(string token)
        {
            if (String.IsNullOrEmpty(token))
            {
                await DisconnectAsync();
            }
            try
            {
                var payload = _jwtHandler.GetTokenPayload(token);
                if (payload == null)
                {
                    await DisconnectAsync();

                    return;
                }
                await SendMessageAsync();
            }
            catch
            {
                await DisconnectAsync();
            }
        }