Javascript/jQuery: Basic auth over multiple requests

时间:2015-11-12 11:03:10

标签: javascript jquery basic-authentication

I am sending an Ajax-GET-requests using basic auth:

$.ajax({
  type: "GET",
  url: url,
  beforeSend: function(xhr){
     xhr.setRequestHeader( "Authorization", "Basic "+btoa("username:password"));
     xhr.setRequestHeader( "Accept", "application/json" );
    },
  success: function(data){
    console.warn(data);
  }
});

This is working perfectly fine - but do I have to send the username/password on every request?

This would mean, that I have to ask the user for his username/password on every request / or store it in Javascript, which is not very safe.

Is there any way to send the username/password only once, even for multiple requests?

Thank you very much!

0 个答案:

没有答案