【问题标题】:Angular ng2-ui-auth and Lumen Socialite not matching request POSTAngular ng2-ui-auth 和 Lumen Socialite 不匹配请求 POST
【发布时间】:2018-10-29 22:42:36
【问题描述】:

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}

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

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

提前致谢

【问题讨论】:

    标签: angular lumen laravel-socialite satellizer


    【解决方案1】:

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

    这是我们在 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(),因为 lumen 不处理会话。

    【讨论】:

      猜你喜欢
      • 2018-01-02
      • 2019-02-24
      • 1970-01-01
      • 2016-08-10
      • 1970-01-01
      • 2018-12-29
      • 2018-10-15
      • 1970-01-01
      相关资源
      最近更新 更多