При интеграции с mailchimp я выполняю аутентификацию после получения access_token, затем я также отправляю запрос на получение метаданных и сталкиваюсь с проблемой.
После синхронизации имени пользователя и пароля я получаю access_token и получаю ошибку в этом коде:
var AccessToken = '<?php //echo $_GET['access_token']; ?>'
jQuery.ajax( {
url: "https://login.mailchimp.com/oauth2/metadata",
type: 'GET',
beforeSend : function( xhr ) {
xhr.setRequestHeader( 'Authorization', 'OAuth ' +
AccessToken );
},
success: function( response ) {
console.info(response);
},
error : function(error) {
console.info(error);
}
} );
Я также пробовал из завитка как:
public function list()
{
$url = 'https://login.mailchimp.com/oauth2/token';
$data = [
'grant_type' => 'authorization_code',
'client_id' => 345555555555555555555555,
'client_secret' => '4b0xxxxxxxxxxxxxxxxxxxxx5406a7d',
'redirect_uri' => 'http://127.0.0.1:8000/success',
'code' => $_GET['code']
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec ($ch);
$err = curl_error($ch); //if you need
curl_close ($ch);
return $response;
}
Access to XMLHttpRequest at 'https://login.mailchimp.com/oauth2/metadata' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Cross-Origin Read Blocking (CORB) blocked cross-origin response https://login.mailchimp.com/oauth2/metadata with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.
send @ jquery.min.js:2
ajax @ jquery.min.js:2
(anonymous) @ list:74
Ошибка в вашем запросе гласит, что КОРБ,
Cross-origin read blocking, better known as CORB, is an algorithm by which dubious cross-origin resource fetches are identified and blocked before they reach a web page. CORB reduces the risk of leaking sensitive data by keeping it further from cross-origin web pages. In most browsers, it keeps such data out of untrusted script execution contexts. In browsers with Site Isolation, it can keep such data out of untrusted renderer processes entirely, helping even against side channel attacks.
Поскольку вы делаете запрос с локального хоста, он считается сомнительным источником, в результате чего он блокируется.
Можете ли вы предложить мне, как получить метаданные из токена доступа в Oauth2