簡體   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