【问题标题】:Laravel Authenticate user from different websiteLaravel 验证来自不同网站的用户
【发布时间】:2016-04-12 21:38:56
【问题描述】:

我有 2 个不同的网站。面向公众的网站使用 Wordpress 开发,项目功能使用 Laravel 开发。

我已经在 Wordpress 中放置了登录表单,并尝试从 wordpress 自定义表单登录到 Laravel 项目模块。但存在与 csrf 令牌不匹配相关的问题。

这是来自 wordpress 网站的代码:

<form role="login" action="http://projectmodule.com/auth/login">
  <input type="text" name="username" />
  <input type="password" name="password" />
  <input type="submit" name="login" value="Login" />
</form>

有什么方法可以在不使用任何 Laravel 包的情况下从 wordpress 到 Laravel 对用户进行身份验证。或者如何仅针对特定路由停止 csrf 令牌验证?

我使用的是 Laravel 5.0 和 Wordpress 4.4 版本。

【问题讨论】:

    标签: php wordpress laravel laravel-5


    【解决方案1】:

    如果您使用 Laravel 5.1,您可以从 CSRF 中间件中排除特定路由。检查文件app\Http\Middleware\VerifyCsrfToken.php

    class VerifyCsrfToken extends BaseVerifier
    {
        /**
         * The URIs that should be excluded from CSRF verification.
         *
         * @var array
         */
        protected $except = [
            'your_route_here'
        ];
    }
    

    对于$except数组中指定的所有路由,中间件不会被执行

    【讨论】:

    • 我用的是Laravel 5.0,这个功能不可用,你知道5.0怎么做吗?
    • 目前没有安装 5.0,但您可以:1) 从使用的中间件列表中删除 CSRF 中间件,或者您可以更改中间件的处理方法,检查其中的路由,并跳过所需路线的 csrf 验证
    【解决方案2】:

    您的问题与CORS(跨站资源共享)有关。

    这是 Tino Tkalec 提供的一步一步实施和理解的好链接。

    http://www.toptal.com/web/cookie-free-authentication-with-json-web-tokens-an-example-in-laravel-and-angularjs

    它的github repo是https://github.com/ttkalec/laravel5-angular-jwt

    您将通过这种方式轻松学习和实施。

    【讨论】:

      【解决方案3】:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-07
        • 2015-12-04
        • 2016-07-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多