Skip to content
Permalink
Browse files

Update credentials with the new authorization upon 401/407 reception

  • Loading branch information
jmillan committed Nov 24, 2012
1 parent 2c9a310 commit 5ed612239d1c746591d988f9a3f24f8b2e38dde6
Showing with 25 additions and 0 deletions.
  1. +23 −0 src/DigestAuthentication.js
  2. +2 −0 src/RequestSender.js
@@ -79,6 +79,29 @@ JsSIP.DigestAuthentication.prototype.authenticate = function(password) {
return this.toString();
};


JsSIP.DigestAuthentication.prototype.update = function(response) {
var authenticate, nonce;

if(response.status_code === 401) {
authenticate = response.parseHeader('www-authenticate');
} else {
authenticate = response.parseHeader('proxy-authenticate');
}

nonce = authenticate.nonce.replace(/"/g,'');

if(nonce !== this.nonce) {
this.nc = 0;
this.nonce = nonce;
}

this.realm = authenticate.realm.replace(/"/g,'');
this.qop = authenticate.qop || null;
this.opaque = authenticate.opaque;
};


JsSIP.DigestAuthentication.prototype.toString = function() {
var authorization = 'Digest ';

@@ -95,6 +95,8 @@ JsSIP.RequestSender.prototype = {
if ( !this.challenged || (this.challenged && !this.staled && challenge.stale) ) {
if (!this.credentials) {
this.credentials = new JsSIP.DigestAuthentication(this.ua, this.request, response);
} else {
this.credentials.update(response);
}

if (response.method === JsSIP.c.REGISTER) {

0 comments on commit 5ed6122

Please sign in to comment.
You can’t perform that action at this time.