如何仅允许api访问android或ios应用程序(laravel)? [英] How to allow api access to android or ios app only(laravel)?
本文介绍了如何仅允许api访问android或ios应用程序(laravel)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在laravel中实现一个api.
我想要的是我的api应该不能从android/ios应用程序以外的任何地方访问.我在Google上搜索后得知我可以使用API KEY.
但是我不确定这是否正确.
当前使用OAuth2进行用户身份验证.
请帮助.
解决方案
您要做的是为每个用户创建一个令牌,将其保存在客户端的设备中,并在客户端发出的每个请求中对其进行验证. >
所以基本上您想:
- 在用户表中为令牌列 用户注册时
- 生成令牌
- 进行登录路由,以便用户使用其电子邮件地址和密码登录,并获取令牌以存储在设备中
- 制作一个中间件,该中间件将检查每个请求中的令牌(登录除外)
我写了一篇与您想要的东西完全相同的文章
What you want to do is to create a token for each user, save it in the client's device , verify it in each request that the client makes.
So basically you want to:
- Make a column for the token in the users table
- generate the token when the user registers
- make a login route so that the user would login with his email,password and he will getback the token to store in the device
- make a middleware that would check for the token in each request ( except for the login )
I wrote an article of the exact same thing you want
这篇关于如何仅允许api访问android或ios应用程序(laravel)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文