Open Closed

MAUI app Unauthorized error #3605


User avatar
0
bradm created

I've followed https://github.com/abpframework/abp-samples/tree/master/MAUI-OpenId for a MAUI app and I'm having trouble with api calls being authenticated after logging in. I can log in fine and I get an access token. I can also see a tenant id in the claims. But any requests to the api that need authentication give me an unauthorized error. In the OidcClient options I have to put LoadProfile = false or I get an error contacting userinfo endpoint. Could this be related to my issue? I've tried both using the dynamic proxies that are generated and the AccessTokenHttpMessageHandler to make http requests and I get the same results for both. Calling methods that don't have an Authorize attribute work fine, calls to methods with an Authorize attribute don't work. What is the proper way to add tenantid to the HttpRequestMessage. I tried request.Headers.Add("Tenant", tenantId); The dynamic proxies are supposed to handle the access token and tenantid. What might I be missing for my api to not know that I'm authenticated and have a tenant? I know this isn't a user issue because all the calls work in the web application for this user. Having trouble getting it to work with MAUI. Thank you for your help. Volo.Abp 5.3


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

    I will check it out.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    We have a MAUI template for commercials now(6.0 version), you can check it.

  • User Avatar
    0
    bradm created

    Thanks. I will check it out.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    ok

  • User Avatar
    0
    bradm created

    Well unfortunately the new MAUI template creates and uses the OpenIddict and the solution I'm working with uses the IdentityServer tables. I was able to get Authorized though and I'm making Get calls okay now. My AuthServer : Authority url was incorrect. But I'm having trouble with posting data.

    I have a CustomersAppService with an Authorize attribute. And I can make calls to a GetListAsync that also has an Authorize attribute.

    This api call works.

    [Authorize(RadixDealerPortalPermissions.Customers.Edit)]
    public virtual async Task<List<CustomerDto>> GetCustomersAsync()
    {
        var items = await _customerRepository.GetListAsync();
        return  ObjectMapper.Map<List<Customer>, List<CustomerDto>>(items);
    }
    
    //And this api call works.
    public virtual async Task<CustomerDto> GetAsync(Guid id)
    {
        return ObjectMapper.Map<Customer, CustomerDto>(await _customerRepository.GetAsync(id));
    }
    
    //But I can't create a customer using this call.
    [AllowAnonymous]
    public virtual async Task<CustomerDto> CreateAsync(CustomerCreateDto input)
    {
        var customer = await _customerManager.CreateAsync(
        input.Name, input.Email, input.Street, input.City, input.State, input.PostalCode, input.UserId
        );
        return ObjectMapper.Map<Customer, CustomerDto>(customer);
    }
    

    The error I get is: The required antiforgery cookie ."AspNetCore.Antiforgery.cdV5uW_Ejgc" is not present. Authorization failed for the request at filter 'Volo.Abp.AspNetCore.Mvc.AntiForgery.AbpAutoValidateAntiforgeryTokenAuthorizationFilter'.

    I'm not exactly sure how to get the AntiforgeryToken and add it to my call. If that's what I need to do. It's not going through my AccessTokenRemoteServiceHttpClientAuthenticator class. Or do you think there's something else that would help me out? Thanks.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Could you share a project with me via email? shiwei.liang@volosoft.com

    I will check it. thanks.

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