dingo / api

A RESTful API package for the Laravel and Lumen frameworks.
BSD 3-Clause "New" or "Revised" License
9.32k stars 1.25k forks source link

Laravel dynamic multi domain with Dingo, Hyn/multi-tenant and restrict domain #1738

Closed kajal98 closed 3 years ago

kajal98 commented 4 years ago

Hello, I want to create one website in Laravel version 7 and Dingo version 3 and Hyn/multi-tenant version 5.6.

I have created one project.. I have a requirement like industry can register on my portal and after that they have their own domain or we can say sub domain like foo.localhost:8000 or bar.localhost:8000. But when i access the domain which is not in my database or anywhere else like test.localhost:8000 it also give access to my all APIs. how can i restrict unwanted domain to access my APIs.

I have also made one middleware but not fruitfull.. Below is the code for the same :

public function handle($request, Closure $next)
    {
        $allowedOrigins = ['foo.localhost:8000', 'bar.localhost:8000'];
        $origin = $_SERVER['HTTP_ORIGIN'];
        if (in_array($origin, $allowedOrigins)) {
            return $next($request)
                ->header('Access-Control-Allow-Origin', $origin)
                ->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE')
                ->header('Access-Control-Allow-Headers', 'Content-Type');
        }
        return $next($request);
    }

Can anyone please help me to solve this problem as soon as possible.

@jasonlewis @thilanga

rutul8897 commented 4 years ago

I am also searching for the same, dynamic multi-domain with dingo API.

Allessia444 commented 4 years ago

Hello @kajal98 and @rutul8897 , if you guys found any idwa for the same just let me know because i am also surfing for laravel APIs with dynamic domain with different database.

@jasonlewis @thilanga if you guys do help to us it will be great!

Thank you in advance!

KrishnaChavda25 commented 4 years ago

Hello everyone! I also want to do the same, dynamic multi-domain with dingo API. If you find anything about this please share it with me. Thanks!

kajal098 commented 4 years ago

Hello, I am also searching for the same if you found any solution then let me know. Thank you in advance!

specialtactics commented 3 years ago

Hey guys

@kajal98 Sorry but from the issue description, it's really not clear to me at all what the problem is and what you are trying to do.

I haven't heard of this hyn/multi-tenant package, but from having a look on their website, I see this as the documentation of how to detect the tenant using domain or sub-domain https://tenancy.dev/docs/tenancy/1.x/identification-http

I don't see a relationship between their documentation and what you are doing with the middlewhere as you describe.

Can you please try and explain better what specifically your problem is, and what you think you need to do in order to solve it?