繁体   English   中英

Angular ng2-ui-auth和Lumen Socialite不匹配请求POST

[英]Angular ng2-ui-auth and Lumen Socialite not matching request POST

ng2-ui-auth如此配置

Ng2UiAuthModule.forRoot({
  baseUrl:'http://localhost:8000',
  loginUrl: '/api/auth/login',
  providers: {
    google: {
      clientId: '....',
      url: '/api/auth/google'
    }
  }
})

将会话数据发送到服务器时,这是POST负载

{
"authorizationData": {
    //the same data sent to the auth endpoint
},
"oauthData": {
    //the data received from the oauth endpoint
},
"userData": {
    //additional data you've provided
}

}

8.0.0 ng2-ui-auth changelog

但是,在Lumen框架中,Socialite期望在对象根目录中同时包含字段coderedirect_uri ,否则将引发以下错误

{“ message”:“客户端错误: POST https:\\/\\/accounts.google.com\\/o\\/oauth2\\/token导致400 Bad Request响应:\\ n {\\ n \\” error \\“:\\ “ invalid_request \\”,\\ n \\“ error_description \\”:\\“缺少必需的参数:code \\” \\ n} \\ n“,” code“:400,” status_code“:500}

我在文档中找不到任何内容。

我是否缺少某些配置? 有人解决了这个问题吗?

提前致谢

这个问题已经很久了,但是这个解决方案可能会帮助遇到这个问题的其他人。

这是我们在Lumen API方面所做的工作:

// Due to the changes in ng2-ui-auth (Angular) we set the fiels to the right place
if (!$request->has('code'))
    $request->request->add(['code' => $request->input('oauthData.code')]);
if (!$request->has('redirect_uri'))
    $request->request->add(['redirect_uri' => $request->input('authorizationData.redirect_uri')]);

// Retrieve the redirectUri
$redirectUri = $request->has('redirectUri') ? $request->get('redirectUri') : $request->get('redirect_uri');

// Inits using the google (stateless) driver
$provider = Socialite::with('google');
$provider->redirectUrl($redirectUri);
$provider->stateless();

实际上,发生的是使用新的ng2-ui-auth(v8 +)时,代码和redirect_uri更改了位置。 因此,在这里,我们只是将它们放在正确的位置(以防万一它不再更改),并且还要确保它可以与旧版本一起使用。 当然,不要忘记保持stateless(),因为流明不能处理会话。

暂无
暂无

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

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