Base solution for your next web application

Activities of "JapNolt"

Another solution that is possible is to use SignalR Groups although admittedly it does require changes in both the hub and also when sending the message. I have some thoughts about this on this other thread: https://support.aspnetzero.com/QA/Questions/11117/Microsoft-signalR-is-not-working-with-multiple-instances#answer-4522399e-6457-858f-7bdc-3a0504ccce6e

EDIT: I posted to soon. The code below works for sending messages to clients but does not help with tracking a count of clients or if a user is online.

I recently encountered the same problem and decided to use the Groups feature in SignalR. This blog article recommended that and per my limited testing, it works well https://consultwithgriff.com/signalr-connection-ids/

In the OnConnectedAsync, I add the connection to a group for the tenant and also to a group for the user. I would recommend that ANZ adopt this approach because I believe it would work with either a single server or a scaled out system.

I am willing to share more code if you wish.

Here's an example of how I extended the AbpCommonHub

` public class AbpCommonHubExtended : AbpCommonHub { private readonly IOnlineClientManager _onlineClientManager;

    public AbpCommonHubExtended(
        IOnlineClientManager onlineClientManager,
        IOnlineClientInfoProvider clientInfoProvider) : base(onlineClientManager, clientInfoProvider)
    {
        _onlineClientManager = onlineClientManager;
    }

    public override async Task OnConnectedAsync()
    {
        await base.OnConnectedAsync();

        var client = _onlineClientManager.GetByConnectionIdOrNull(Context.ConnectionId);

        await Groups.AddToGroupAsync(
            client.ConnectionId,
            GetGroupName_AllClientsForTenant(
                client.TenantId.GetValueOrDefault()));

        await Groups.AddToGroupAsync(
            client.ConnectionId,
            GetGroupName_AllClientsForUser(
                client.TenantId.GetValueOrDefault(),
                client.UserId.GetValueOrDefault()));
    }

    public static string GetGroupName_AllClientsForTenant(int tenantId)
    {
        return $"t_{tenantId}";
    }
    public static string GetGroupName_AllClientsForUser(int tenantId, long userId)
    {
        return $"t_{tenantId}_u_{userId}";
    }
}

`

Thanks @ismcagdas,

I came up with a similar solution. I added a non-existant "page" to the path.

    this._accountService.impersonateTenant(input).subscribe((result: ImpersonateOutput) => {
        let targetUrl =
            this._appUrlService.getAppRootUrlOfTenant(result.tenancyName) +
            'it?impersonationToken=' +
            result.impersonationToken;
        if (input.tenantId) {
            targetUrl = targetUrl + '&tenantId=' + input.tenantId;
        }

        this._authService.logout(true, targetUrl);
    });

note the "it" before ?impersonationToken

@ismcagdas Any update?

I'm sorry Ismail, but I'm struggling to understand how I can incorporate On-Behalf-Of flow into ANZ Can you give some more detail after reading the below docs?

https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/on-behalf-of

Thanks for the additional information! I'm assuming I need the ability to SaveTokens as described here but I don't know where to configure that in ANZ. Also how would I access them later when needed in an app service?

This feels kludgy. What about token refresh, etc?

Isn't there some interface I can implement or a class I can override to implement AAD more deeply in the product?

I'm sorry that it's been awhile and I got sidetracked. The use case is similar to this auth flow https://github.com/Azure-Samples/active-directory-dotnet-native-aspnetcore-v2/tree/master/2.%20Web%20API%20now%20calls%20Microsoft%20Graph. I want to make a request to Graph through our WebAPI on behalf of the user (delegated auth). Our frontend is Angular so the concept would be similar to this sample.

Since my problem is the same as the original poster, I was hoping you would be able to post the solution that you sent to him since it was just demo code anyway. I try to do my due diligence by searching for existing solutions instead of posting a new question as soon as I have a problem.

@maliming @fvdh Please share the solution to this problem with the rest of us.

Showing 11 to 20 of 37 entries