Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if request came from mobile or web

Is there a way for Passport to check if request came from mobile or web app when doing authentication? Because if request came from the web I want to return a view otherwise return a json payload.

like image 651
Jay Avatar asked Jan 23 '18 03:01

Jay


1 Answers

This is my opinion,you can check user-agent in the request header ,its look like this(came from windows):

user-agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36

and this is came from my iPhone

User-Agent:Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1

and this is Android

User-Agent:Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Mobile Safari/537.36

so you can figer it out from user-agent,which request came from mobile or pc

like image 185
Yang St Avatar answered Sep 30 '22 06:09

Yang St