|
@@ 171-175 (lines=5) @@
|
| 168 |
|
$opaque = md5(uniqid()); |
| 169 |
|
|
| 170 |
|
// No digest string? Then you're done. Go home. |
| 171 |
|
if (empty($digest_string)) |
| 172 |
|
{ |
| 173 |
|
$this->ci->output->set_header( sprintf('WWW-Authenticate: Digest realm="%s", nonce="%s", opaque="%s"', config_item('api.realm'), $nonce, $opaque) ); |
| 174 |
|
return false; |
| 175 |
|
} |
| 176 |
|
|
| 177 |
|
// Grab the parts from the digest string. |
| 178 |
|
// They will be provided as an array of the parts: username, nonce, uri, nc, cnonce, qop, response |
|
@@ 183-187 (lines=5) @@
|
| 180 |
|
preg_match_all('@(username|nonce|uri|nc|cnonce|qop|response)=[\'"]?([^\'",]+)@', $digest_string, $matches); |
| 181 |
|
$digest = (empty($matches[1]) || empty($matches[2])) ? array() : array_combine($matches[1], $matches[2]); |
| 182 |
|
|
| 183 |
|
if (! array_key_exists('username', $digest)) |
| 184 |
|
{ |
| 185 |
|
$this->ci->output->set_header( sprintf('WWW-Authenticate: Digest realm="%s", nonce="%s", opaque="%s"', config_item('api.realm'), $nonce, $opaque) ); |
| 186 |
|
return false; |
| 187 |
|
} |
| 188 |
|
|
| 189 |
|
// Set email for later throttling check |
| 190 |
|
if (config_item('api.auth_field') === 'email') |
|
@@ 216-220 (lines=5) @@
|
| 213 |
|
} |
| 214 |
|
$valid_response = md5($A1 .':'. $digest['nonce'].':'. $digest['nc'] .':'. $digest['cnonce'] .':'. $digest['qop'] .':'. $A2); |
| 215 |
|
|
| 216 |
|
if ($digest['response'] != $valid_response) |
| 217 |
|
{ |
| 218 |
|
$this->ci->output->set_header( sprintf('WWW-Authenticate: Digest realm="%s", nonce="%s", opaque="%s"', config_item('api.realm'), $nonce, $opaque) ); |
| 219 |
|
return false; |
| 220 |
|
} |
| 221 |
|
|
| 222 |
|
$this->user = $user; |
| 223 |
|
|