Starts in:
1 DAY
23 HRS
29 MIN
37 SEC
Starts in:
1 D
23 H
29 M
37 S

Activities of "Leonardo.Willrich"

Thank you!

Yes, this one is working. Is the same content?

Thank you Maliming, it seems to be working. It seems that still hangs waiting for an answer from the server and shows the message, but, next the user is redirected to the login page as expected. I'll do some more tests!

Hi Maliming,

It will always redirect to the login, even if the user session/token is valid. Let's suppose if the user tries to access a Method in a service that he doesn't have access, then, the same message will be shown. In this case, he will be redirected to the login page and won't have a chance to see the message and why he was redirected. But, if the session/token is expired, it will work, I'm just worried about the previous scenario. So, before redirecting, is possible to double-check if the token is the problem?

Just one more piece of information, injecting ICurrentUser, the property IsAuthenticated still has value true, which is wrong.

Hi Maliming,

Thank you for your answer. I've did that, but, it is still not working. The problem is that the AuthorizeRouteView doesn't fail and the code in NotAuthorized doesn't execute. So, the page gets rendered. But, when calling the API methods, it is throwing the error 401 - Unauthorized. I've tried to check the property IsAuthenticated outside the <NotAuthorized>, but, the variable context doesn't exist.

To test that, I just access a page, clear all site data, and move to the next menu. I can see that the router is called, but, it shows that the use is authorized, but, when calling the API method it doesn't work. In this case, I'd like to have the user redirect to the login page.

Hi Maliming,

I have cleared all site date for both applications (ABP.IO and third-party sites) and it seems to be working now.

Here is the Context.User:

It will return the current Token.

public async Task<string> GetAccessToken()
        {
            _logger.LogDebug("AccessTokenManager.GetAccessToken - Starting...");
            await CheckAccessToken();
            if (_currentAccessToken == null || string.IsNullOrEmpty(_currentAccessToken.AccessToken))
            {
                _logger.LogDebug("AccessTokenManager.GetAccessToken - Redirecting to Login page");
                _navigationManager.NavigateTo("account/login");
            }
            _logger.LogDebug("AccessTokenManager.GetAccessToken - Completed");
            return _currentAccessToken?.AccessToken;
        }

The _currentAccessToken was requested during the login and stored.

My hub is very simple, here is the code:

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
using TVD_Holdings_Ltd.SBC.SignalRHub;
using TVD_Holdings_Ltd.SBC.UIEventNotifications;
using Volo.Abp.AspNetCore.SignalR;

namespace TVD_Holdings_Ltd.SBC.UsersPresence
{
    [HubRoute("/sbcUserPresence")]
    public class UsersPresenceSignalRHub : AbpHub
    {
        private readonly ILogger<UsersPresenceSignalRHub> _logger;
        private readonly IUserPresenceAppService _userPresenceAppService;
        internal static ConcurrentDictionary<string, Guid> Users = new ConcurrentDictionary<string, Guid>();

        public UsersPresenceSignalRHub(ILogger<UsersPresenceSignalRHub> logger, IUserPresenceAppService userPresenceAppService)
        {
            _logger = logger;
            _userPresenceAppService = userPresenceAppService;
        }

        public override async Task OnConnectedAsync()
        {
            _logger.LogDebug("UsersPresenceSignalRHub.OnConnectedAsync => CurrentUser.Id: {0}", CurrentUser.Id);
            if (CurrentUser != null && CurrentUser.Id.HasValue && CurrentTenant.Id.HasValue)
            {
                await Groups.AddToGroupAsync(Context.ConnectionId, CurrentTenant.Id.GetValueOrDefault().ToString());

                Users.TryAdd(Context.ConnectionId, CurrentUser.Id.GetValueOrDefault());

                if (Users.Count(x => x.Value == CurrentUser.Id.GetValueOrDefault()) == 1)
                {
                    _logger.LogDebug("UsersPresenceSignalRHub.OnConnectedAsync => Setting CurrentUser.Id: {0} as LoggedIn", CurrentUser.Id);
                    await _userPresenceAppService.SetUserLoggedIn();
                }
            }
        }

        public override async Task OnDisconnectedAsync(Exception exception)
        {
            _logger.LogDebug("UsersPresenceSignalRHub.OnDisconnectedAsync => CurrentUser.Id: {0}", CurrentUser.Id);
            if (CurrentUser != null && CurrentUser.Id.HasValue && CurrentTenant.Id.HasValue)
            {
                await Groups.RemoveFromGroupAsync(Context.ConnectionId, CurrentTenant.Id.GetValueOrDefault().ToString());

                Users.TryRemove(Context.ConnectionId, out Guid userId);
                if (Users.Count(x => x.Value == CurrentUser.Id.GetValueOrDefault()) == 0)
                {
                    _logger.LogDebug("UsersPresenceSignalRHub.OnDisconnectedAsync => Setting CurrentUser.Id: {0} as LoggedOut", CurrentUser.Id);
                    await _userPresenceAppService.SetUserLoggedOut();
                }
            }
        }
    }
}

Here is how the Client (Blazor WASM app) is connecting:

presenceHub = new HubConnectionBuilder()
                .WithUrl(baseUrl + "/sbcUserPresence")
                .WithAutomaticReconnect(new SignalRRetryPolicy())
                .Build()
                .AssignConnectionEvents("User Presence");
            await presenceHub.StartAsync();

I've tried to send the Token as well, but, it didn't changed:

presenceHub = new HubConnectionBuilder()
                .WithUrl(baseUrl + "/sbcUserPresence", options =>
                {
                    options.AccessTokenProvider = GetAccessToken;
                })
                .WithAutomaticReconnect(new SignalRRetryPolicy())
                .Build()
                .AssignConnectionEvents("User Presence");
            await presenceHub.StartAsync();

Maliming,

The CurrentUser.Name and Surname is still empty. I couldn't find HttpContext property. My application is using Services (.Application), I don't have a controller in the .Host application.

Following this post, https://github.com/abpframework/abp/issues/6571, I've added AbpClaimsTypes.Name and AbpClainmsTypes.Surname in the IdentityServerDataSeeder, it created the two new ApiResouceClaims records, but, didn't work. I've restarted all applications to see if it would be a cache issue, but, still not working.

Any idea what else I can do?

Showing 31 to 40 of 145 entries
Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06