Answer the question
In order to leave comments, you need to log in
Do I need to specify AllowCredentials = true for CORS basic http authorization?
Hello. The question arose: I can’t authorize a user on a third-party API domain in any way.
As a server using yii2, here is the cors filter configuration:
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['corsFilter'] = [
'class' => \yii\filters\Cors::className(),
'cors' => [
'Origin' => ['*'],
'Access-Control-Request-Headers' => ['X-Authentication', 'Authorization'],
'Access-Control-Request-Methods' => ['OPTIONS', 'GET', 'PUT', 'PATCH', 'DELETE', 'POST']
//'Access-Control-Allow-Credentials' => true,
]
];
$behaviors['authenticator'] = [
'class' => HttpBasicAuth::className(),
'auth' => [$this, 'auth'],
'except' => ['options']
];
return $behaviors;
}
function sendToken() {
var username = $("input#login").val();
var password = $("input#password").val();
var token = "Basic " + btoa(username + ":" + password);
console.log(token);
$.ajax({
url: 'http://admin.tech.local/api/voyages',
type: 'GET',
crossDomain: true,
success: function (){
alert('Thanks for your comment!');
},
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', token);
}
})
}
Answer the question
In order to leave comments, you need to log in
And how do cookies depend on the fact that you do not have a session?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question