Base solution for your next web application
Open Closed

Public Facing API #5017


User avatar
0
cyklussoftware created

I am using ASP.NET Core + jQuery v5.3.

I am looking at creating a public-facing API so that calendar services like Google Calendar or Outlook can request an ICS representation of a set of Event entities from our DB.

I will be generating the individual URLs for accessing the API within the application, so we will know the user's ID and the tenant's ID. We can embed this information into the URL and the API will know what to access.

The question ultimately becomes, with ASP.NET Zero / ASP.NET Boilerplate, how would I create an API that DOESN'T require the user to log in? Would I just use the normal ASP.NET Core way or is there a better way?

Thanks!


4 Answer(s)
  • User Avatar
    0
    bbakermmc created

    Just create an end point and allow anonymous access

  • User Avatar
    0
    cyklussoftware created

    Right. I see AllowAnonymous for MVC controllers and AbpAllowAnonymous for AppService methods, but how do I access a specific repository without having a logged in user? Is there any build-in system for this? Or will it need to be a custom system like: access host DB, look for tenant DB based on URL parameter, then access tenant DB?

  • User Avatar
    0
    cyklussoftware created

    I know about the GET request header called "Abp.TenantId", but because I want to return an ICS file using the URL ONLY and NOT through a GET request, I am having trouble.

    I could create an [AllowAnonymous] MVC Controller method that takes in the tenantId as a parameter. The method can create and execute a new GET request with the Abp.TenantId header set. This will give me access to the AppService and its repositories. Once the [AllowAnonymous] MVC Controller method has the JSON data from the AppService's response, I can parse it and return the file.

    Is there a better way to do this?

  • User Avatar
    0
    aaron created
    Support Team

    From the documentation on Multi-Tenancy:

    While working on a multi-tenant application database, we can get the current tenant. By default, it's obtained from the IAbpSession. We can change this behavior and switch to another tenant's database. Example:

    public virtual List<Product> GetProducts(int tenantId)
    {
       using (_unitOfWorkManager.Current.SetTenantId(tenantId))
       {
           return _productRepository.GetAllList();
       }
    }