重定向到 Microsoft 登录页面时出现 Microsoft Graph 的 cors 问题
when redirecting to Microsoft sign in page getting cors issue for microsoft graph
我正在开发 laravel api 并且 UI 是 angularjs ,问题是重定向到 Microsoft 登录页面时获取 Microsoft 图形的 cors 问题,问题是
XMLHttpRequest cannot load
https://reservations-api.nymblpro.com/coordinator/event. Redirect from
'https://reservations-api.nymblpro.com/coordinator/event' to
'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?state=cuSlE1…rect_uri=https%3A%2F%2Freservations-api.nymblpro.com%2Fcoordinator%2Fevent'
has been blocked by CORS policy: Request requires preflight, which is
disallowed to follow cross-origin redirect.
我尝试设置 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());
}
}
看起来您的 AngularJs 应用程序将调用您的 Laravel 应用程序的 api,returns 授权 url,然后是您的 [=21] =] 前端将在 AJAX 函数中调用此 url 。所以这应该是罪犯。
您可以尝试修改 angularjs 前端应用程序中的代码,将 $http.get()
函数更改为:
// similar behavior as an HTTP redirect
window.location.replace("http://whosebug.com");
// similar behavior as clicking on a link
window.location.href = "http://whosebug.com";
否则,您可以尝试在 angularjs 应用程序中使用 adal for js。有关详细信息,请参阅 https://github.com/AzureAD/azure-activedirectory-library-for-js。
我正在开发 laravel api 并且 UI 是 angularjs ,问题是重定向到 Microsoft 登录页面时获取 Microsoft 图形的 cors 问题,问题是
XMLHttpRequest cannot load https://reservations-api.nymblpro.com/coordinator/event. Redirect from 'https://reservations-api.nymblpro.com/coordinator/event' to 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?state=cuSlE1…rect_uri=https%3A%2F%2Freservations-api.nymblpro.com%2Fcoordinator%2Fevent' has been blocked by CORS policy: Request requires preflight, which is disallowed to follow cross-origin redirect.
我尝试设置 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());
}
}
看起来您的 AngularJs 应用程序将调用您的 Laravel 应用程序的 api,returns 授权 url,然后是您的 [=21] =] 前端将在 AJAX 函数中调用此 url 。所以这应该是罪犯。
您可以尝试修改 angularjs 前端应用程序中的代码,将 $http.get()
函数更改为:
// similar behavior as an HTTP redirect
window.location.replace("http://whosebug.com");
// similar behavior as clicking on a link
window.location.href = "http://whosebug.com";
否则,您可以尝试在 angularjs 应用程序中使用 adal for js。有关详细信息,请参阅 https://github.com/AzureAD/azure-activedirectory-library-for-js。