Open Closed

Maui blazor app Exception error (Cannot invoke JavaScript outside of a WebView context.) #4326


User avatar
0
yasin.hallak.89@gmail.com created
  • ABP Framework version: v7.0.0
  • UI type:Maui Blazor
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:

An error occurred during the initialize Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor phase of the module Volo.Abp.AspNetCore.Components.MauiBlazor.AbpAspNetCoreComponentsMauiBlazorModule, Volo.Abp.AspNetCore.Components.MauiBlazor, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null: Cannot invoke JavaScript outside of a WebView context.

  • Steps to reproduce the issue:"

Hi support.

I have created project with Ui MauiBlazor from abp suite.

First : I run HttpApi.Host project.

Second: I run MauiBlazor project as andriod emulator and give me this error as above.

Can you give me some solution please


12 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    I'd like to check it remotely, can we have a meeting? shiwei.liang@volosoft.com

  • User Avatar
    0
    yasin.hallak.89@gmail.com created

    Hi,

    I'd like to check it remotely, can we have a meeting? shiwei.liang@volosoft.com

    Yes we can I sent you invitation on google meet

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    It's working for me

    Will it work if you run an MAUI-Blazor app without ABP?

    It may be related to your local environment, you can try it on a new computer.

  • User Avatar
    0
    yasin.hallak.89@gmail.com created

    It's strange !!! . I have created new project without ABP It works well.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Could you try to run it in an emulator? As you know, I can't operate your physical device in the meeting, it's hard to find the problem

  • User Avatar
    0
    yasin.hallak.89@gmail.com created

    Could you try to run it in an emulator? As you know, I can't operate your physical device in the meeting, it's hard to find the problem

    Now it's work for me , I have Updated Operating System and reinstall Visual Studio

  • User Avatar
    0
    yasin.hallak.89@gmail.com created

    Can I login with mobile without redirect to web page ?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Yes, you can.

    We use code flow by default, but if you want, you can use the password flow

    You can check this to know how to get access token with password flow:https://github.com/abpframework/abp/blob/dev/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/ClientDemoService.cs#L61-L69

  • User Avatar
    0
    yasin.hallak.89@gmail.com created

    Hi,

    Yes, you can.

    We use code flow by default, but if you want, you can use the password flow

    You can check this to know how to get access token with password flow:https://github.com/abpframework/abp/blob/dev/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/ClientDemoService.cs#L61-L69

    Thanx.

    Just we need to change type from code-flow to the password-flow in configuration and we can login without redirect to web page ?.

    Or we need to do some other changes in code ?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Just we need to change type from code-flow to the password-flow in configuration and we can login without redirect to web page ?.

    No, you need to create your own login page.

    And update ExternalAuthService to use password flow instead of oidcClient

  • User Avatar
    0
    yasin.hallak.89@gmail.com created

    Hi,

    Just we need to change type from code-flow to the password-flow in configuration and we can login without redirect to web page ?.

    No, you need to create your own login page.

    And update ExternalAuthService to use password flow instead of oidcClient

    Hi,

    I didn't find any where within OicdClinet to set grantType password flow

    Could you write some hints or steps to change to password flow Please

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    I didn't find any where within OicdClinet to set grantType password flow

    It's not easy, you need a lot of work to do.

    • Create a login page
    • Remove all OidcClient and MauiAuthenticationBrowser used
    • Update ExternalAuthService, for example:
    public async Task<LoginResult> LoginAsync(string userNameOrEmailAddress, string password)
    {
        var client = _httpClientFactory.CreateClient();
        var discoveryDocument = await client.GetDiscoveryDocumentAsync(configuration["OAuthConfig:Authority"]);
    
        var passwordTokenRequest = new PasswordTokenRequest
        {
            Address = discoveryDocument.TokenEndpoint,
            ClientId = configuration["OAuthConfig:ClientId"],
            UserName = userNameOrEmailAddress,
            Password = password,
            Scope = configuration["OAuthConfig:Scope"]
        };
    
        var tokenResponse = await client.RequestPasswordTokenAsync(passwordTokenRequest);
        await _myProjectNameApplicationSettingService.SetAccessTokenAsync(tokenResponse.AccessToken);
        _currentUser = new ClaimsPrincipal(new ClaimsIdentity(new JwtSecurityTokenHandler().ReadJwtToken(tokenResponse.AccessToken).Claims, AuthenticationType));
        UserChanged?.Invoke(_currentUser);
    
        return LoginResult.Success();
    }
    
    public async Task SignOutAsync()
    {
        await _myProjectNameApplicationSettingService.SetAccessTokenAsync(null);
        
        _currentUser = new ClaimsPrincipal(new ClaimsIdentity());
        UserChanged?.Invoke(_currentUser);
    }
    
Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09