Home > Back-end >  Determine whether the request is coming from mobile app
Determine whether the request is coming from mobile app

Time:02-28

I've developed a mobile app(ionic, angular) and a web app(Laravel). When I click on the (Feedback) button on mobile app then it will open the mobile browser and will be navigated to webapp/feedback page. InAppBrowser is used for that.

From web app, I need to identify whether the request came from the mobile app. Because that link should not be able to opened directly. Is there any specific way to do this?

CodePudding user response:

Use Cordova InAppBrowser directly or with the Ionic wrapper and use the target of _self. It should open in the webview.

E.g

cordova.InAppBrowser.create('https://somewebsite.com/', '_self', 'usewkwebview=yes')

Edit: If you want to accept only your mobile app, you need to create middleware

E.g

php artisan make:middleware EnsureIsMobileApp

IN EnsureIsMobileApp middleware

public function handle($request, Closure $next)
    {
        if ($request->input('token') !== 'Jjfi393ij9w') { //random secret code
            abort(403, 'Unauthorized action.');
        }
        unset($request['token']); //if you want to remove token
        return $next($request);
    }

Call form your app

https://somewebsite.com/?token=Jjfi393ij9w
  • Related