我開發laravel API和UI是angularjs,問題是在頁面獲取CORS問題重定向到微軟標誌的微軟圖形時,這個問題是頁面獲取CORS問題重定向時微軟標誌的微軟圖形
XMLHttpRequest無法加載 https://reservations-api.nymblpro.com/coordinator/event。從 'https://reservations-api.nymblpro.com/coordinator/event' 重定向到 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?state=cuSlE1 ... rect_uri = HTTPS%3A%2F%2Freservations-api.nymblpro.com%2Fcoordinator%2Fevent' 已被阻止通過CORS政策:請求需要預檢,這是不允許的 跟隨橫 - 原始重定向。
我試着設置cors中間件仍然是我得到同樣的問題。 我的代碼如下:
public function get_microsoft_token(Request $request)
{
$provider = new \League\OAuth2\Client\Provider\GenericProvider([
'clientId' => 'fd482697-fd9f-46ac-ab3a-727e47517c8b',
'clientSecret' => 'WZOh3qLz7ZQyKemCQf3RsCF',
'redirectUri' => 'https://reservations-api.nymblpro.com/coordinator/event',
'urlAuthorize' => 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
'urlAccessToken' => 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
'urlResourceOwnerDetails' => '',
'scopes' => 'openid calendars.readwrite'
]);
if (!$request->has('code')) {
return redirect($provider->getAuthorizationUrl());
}
else {
$accessToken = $provider->getAccessToken('authorization_code', [
'code' => $request->input('code')
]);
return ($accessToken->getToken());
}
}
http://stackoverflow.com/questions/40388152/microsoft-graph-download-file-content-returns-404/40400293#40400293和http://stackoverflow.com/questions/34949492/cors-request-with -preflight-and-redirect-disallowed-workarounds/39728229#39728229可能與此有關 – sideshowbarker
如果您還發布了發送請求的客戶端JavaScript代碼的相關部分,這將會很有幫助。 – sideshowbarker
@sideshowbarker這裏是JavaScript'$ scope.getTokenForCalender = function() { var url =「https://reservation-api.dev/coordinator/event」; (函數(結果){ console.log(「Token For Calender Integration - 」+ JSON.stringify(result)); },function(err) console.log(JSON.stringify(err)); alert(「Error Occured ....」); }); } $ scope.getTokenForCalender(); 這裏err爲空 –