简体   繁体   English

在Lumen中设置OAuth2

[英]Setup OAuth2 in Lumen

I followed this article written to setup OAuth2 for my API that I'm writing in Lumen . 我按照这篇文章写了为我的API设置OAuth2,我在Lumen写的。 I finished setting it up and I implemented the client so that I could test that it works. 我完成了设置并实现了客户端,以便我可以测试它是否有效。 I haven't been able to get it to work. 我无法让它发挥作用。 When I click the 'Login to API' button, it sends a POST to http://myserver.com/login and it never finishes. 当我点击“登录到API”按钮时,它会向http://myserver.com/login发送一个POST,它永远不会完成。 It hangs here and I get no exceptions or errors of any kind. 它挂在这里,我没有任何例外或错误。 Also, when it hangs like that I cannot just refresh the page. 此外,当它挂起时,我不能只刷新页面。 I have to serve it on another port, if that's a clue as to what's happening. 我必须在另一个端口上提供它,如果这是一个关于发生了什么的线索。 I output a bunch of log messages and I've narrowed the trouble down to this: 我输出了一堆日志消息,我把问题缩小到这个:

$guzzleResponse = $client->post(sprintf('%s/oauth/access-token', $config->get('app.url')), [
            'body' => $data
        ]);

I checked the parameters and they look good. 我检查了参数,看起来很好。 $client is a GuzzleHttp Client. $client是一个GuzzleHttp客户端。 The post method inside looks like this: post方法里面看起来像这样:

public function post($url = null, array $options = [])
{
    return $this->send($this->createRequest('POST', $url, $options));
}

I think I may have to enable cookies in Lumen. 我想我可能要在Lumen中启用cookie。 Where would I go to find that out? 我会在哪里找到它? Does anyone have any other ideas? 有没有人有任何其他想法?

To enable cookie, you can do this in .env file - 要启用cookie,您可以在.env文件中执行此操作 -

SESSION_DRIVER=cookie

Then run composer update command. 然后运行composer update命令。

如果你没有检查你的.env?..请添加AUTH_MODEL = App \\ Auth \\ User。

Sometimes Guzzle doesnot work with port eg localhost:8888. 有时Guzzle不能使用端口,例如localhost:8888。 If you are runnnig your server on some port change it to default 80 and guzzle will work 如果您在某个端口上运行服务器,则将其更改为默认值80并且guzzle将起作用

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

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