简体   繁体   English

Laravel外部(来自另一个域)api请求,以检查用户是否登录到服务器(主服务器)中

[英]Laravel external(from another domain) api request to check if the user is logged in a server (main server)

How can I make a logged-in-check via an external call (external domain) to a main server? 如何通过外部呼叫(外部域)对主服务器进行登录检查? Should be a js client-server call. 应该是js客户端-服务器调用。

In other words domain1.com makes a client-server call to the main-domain.com to check if the user is already logged-in in main-domain.com 换句话说,domain1.com对main-domain.com进行客户端-服务器调用,以检查用户是否已经登录main-domain.com。

What you are looking for is crossdomain request with cookies, this requires that you must specify some header output on the domains, you can find more information @ this stackoverflow link . 您要查找的是带有cookie的跨域请求,这要求您必须在域上指定一​​些标头输出,您可以在此stackoverflow链接中找到更多信息。

You'll need some kind of handler on the main domain that can start the session, verify that it has the necessary session data that says its logged in and return true/false for the caller. 您将在主域上需要某种处理程序来启动会话,验证其是否具有表明已登录的必要会话数据,并为调用方返回true / false。

According to me, easiest way is to maintain a flag in your main domain. 据我说,最简单的方法是在您的主域中保留一个标志。 So what you need to do is. 因此,您需要做的是。

  1. Add one field in users table, let's say isLoggedIn 在用户表中添加一个字段,例如isLoggedIn

  2. Create an API which return true or false when you make a call from domain1.com 创建一个API,当您从domain1.com拨打电话时返回true或false

  3. Handle data based on the result of the API. 根据API的结果处理数据。

There are two ways you can: 您可以通过两种方式:

  • Use simply api token authentication on main domain. 在主域上仅使用api令牌身份验证。
  • Setup OAuth on main domain. 在主域上设置OAuth。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM