Open Closed

Microservices template + blazor server UI + azure signalr #3070


User avatar
0
James2311 created

Hello,

We are running into an unauthorized errors when we navigate to pages that require calls to authenticated endpoints such as the Users page from the Identity module.

Please do not share your projects in public website.

Steps to reproduce error

  1. You might need to install yarn before running the app
  2. Please add azure SIGNAL R connectionstring in Blazor apps-> BlazorServerSignalRTestBlazorModule.cs file
  3. Run the Tye
  4. Open Blazor app
  5. Login with ABP default credentials
  6. Go to Products page and you see “Unauthorized error”

Observe message "No data available" remains, unhandled exceptions in the browser console, UI crashes,

Here are some logs from the blazor server app:

[16:11:31 WRN] Could not find IdentityClientConfiguration for AbpIdentity. Either define a configuration for AbpIdentity or set a default configuration.
[16:11:31 INF] Start processing HTTP request GET https://localhost:44325/api/identity/users/assignable-roles?api-version=1.0
[16:11:31 INF] Sending HTTP request GET https://localhost:44325/api/identity/users/assignable-roles?api-version=1.0
[16:11:31 INF] Received HTTP response headers after 68.6132ms - 401
[16:11:31 INF] End processing HTTP request after 68.7065ms - 401
[16:11:31 WRN] Unhandled exception rendering component: Unauthorized
Volo.Abp.Http.Client.AbpRemoteCallException: Unauthorized
   at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.ThrowExceptionForResponseAsync(HttpResponseMessage response)
   at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync(ClientProxyRequestContext requestContext)
   at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync[T](ClientProxyRequestContext requestContext)
   at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync[T](String methodName, ClientProxyRequestTypeValue arguments)
   at Volo.Abp.Identity.ClientProxies.IdentityUserClientProxy.GetAssignableRolesAsync()
   at Volo.Abp.Identity.Pro.Blazor.Pages.Identity.UserManagement.OnInitializedAsync()
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
[16:11:31 ERR] Unhandled exception in circuit '367ouGPcd8Y1QK8pIIPjkeTSiVhqqC9t3DzqGZ_rpl8'.
Volo.Abp.Http.Client.AbpRemoteCallException: Unauthorized
   at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.ThrowExceptionForResponseAsync(HttpResponseMessage response)
   at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync(ClientProxyRequestContext requestContext)
   at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync[T](ClientProxyRequestContext requestContext)
   at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync[T](String methodName, ClientProxyRequestTypeValue arguments)
   at Volo.Abp.Identity.ClientProxies.IdentityUserClientProxy.GetAssignableRolesAsync()
   at Volo.Abp.Identity.Pro.Blazor.Pages.Identity.UserManagement.OnInitializedAsync()
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)`

Any help would be appreciated.

Thanks,


17 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    What are logs of API website?

  • User Avatar
    0
    James2311 created

    hi

    What are logs of API website?

    Hi,

    I'm not sure which API are you asking? I already provided sample project to reproduce the issue. If you follow the steps you will able to get the error with exception.

    Thanks, James

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Please do not share your projects in public website.

    you can send the sample project to me liming.ma@volosoft.com

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Please try to reproduce your problem using the template project instead of sharing your complex project.

  • User Avatar
    0
    James2311 created

    Hi,

    FYI, We Generated ABP Microservice Solution using ABP Suite. So, not sure why you think its complex project? Its simple ABP Microsservice solution project.

    I send out email again with project download link.

    Thanks, James

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    What's your abp packages version?

  • User Avatar
    0
    James2311 created

    hi

    What's your abp packages version?

    Hi,

    We used ABP version 5.2.1. Also, I sent you email with updated link to download project.

    Thanks, James

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Please also share a ConnectionString with me. I don't have auzre account.

  • User Avatar
    0
    James2311 created

    hi

    Please also share a ConnectionString with me. I don't have auzre account.

    I sent connection string to your email.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Add MyHttpContextIdentityModelRemoteServiceHttpClientAuthenticator to your blazor app.

    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Authentication;
    using Volo.Abp.DependencyInjection;
    using Volo.Abp.Http.Client.IdentityModel.Web;
    using Volo.Abp.IdentityModel;
    
    namespace BlazorServerSignalRTest.Blazor;
    
    [Dependency(ReplaceServices = true)]
    public class MyHttpContextIdentityModelRemoteServiceHttpClientAuthenticator : HttpContextIdentityModelRemoteServiceHttpClientAuthenticator
    {
        public MyHttpContextIdentityModelRemoteServiceHttpClientAuthenticator(IIdentityModelAuthenticationService identityModelAuthenticationService)
            : base(identityModelAuthenticationService)
        {
        }
    
        protected override async Task<string> GetAccessTokenFromHttpContextOrNullAsync()
        {
            var httpContext = HttpContextAccessor?.HttpContext;
            if (httpContext == null)
            {
                return null;
            }
    
            var token = await httpContext.GetTokenAsync("access_token");
            if (token == null)
            {
                var authenticateResult  = await httpContext.AuthenticateAsync("Cookies");
                if (authenticateResult.Succeeded)
                {
                    token = authenticateResult.Properties.GetTokenValue("access_token");
                }
            }
    
            return token;
        }
    
    }
    
    
  • User Avatar
    0
    James2311 created

    Thanks for your response.

    Can you please also tell how to use "MyHttpContextIdentityModelRemoteServiceHttpClientAuthenticator" and access token? Because here you mention to add class but not sure how to use it.

    Thanks, James

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    You just need to add it to your blazor project. That's it.

  • User Avatar
    0
    James2311 created

    Hi,

    Still getting error

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Can you set a breakpoing to confirm the MyHttpContextIdentityModelRemoteServiceHttpClientAuthenticator working?

  • User Avatar
    0
    James2311 created

    Yes, MyHttpContextIdentityModelRemoteServiceHttpClientAuthenticator working and getting access_token but still having error about signalr connected state that I already mentioned above.

    As you already have our sample app and signal r connection string, can you please let us know how to resolve it?

    Thanks

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    It worked before. I will check again.

  • User Avatar
    0
    James2311 created

    FYI, New solution is working. Thanks for help.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 10, 2024, 06:38