Activities of "Leonardo.Willrich"

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.

  • ABP Framework version: v5.3
  • UI type: Blazor WASM
  • DB provider: EF Core

Hi,

I'm using the Blazor WASM template and when the user gets his session expired it is showing error 401 - unauthorized when changing pages instead of redirecting to the login page. Is there a way to redirect to the login page? If I try to access the website using the web browser address, it redirects to the login page correctly. The problem is only if I leave the web browser opened and on stand-by (overnight) and then I try to interact with menus, for example.

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();
  • ABP Framework version: v5.3
  • UI type: Blazor
  • DB provider: EF Core

Hi,

I have a third-party application that is using an access token to access the Web API method. It is working well so far. But, I need to send some real-time notifications to this application from my server and I'm using SignalR to do it. The problem is that the CurrentUser is null or has an invalid value. How to get the CurrentUser instance valid in the AbpHub implementation class? What parameters I should send when connecting to the hub?

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 1 to 10 of 152 entries
Made with ❤️ on ABP v8.3.0-preview Updated on July 05, 2024, 15:13