Validates that the response contains WWW-Authenticate header with a scheme BEARER and, if so, extracts parameters from the header. Otherwise, returns Error.
| 483 | // a scheme BEARER and, if so, extracts parameters from the header. |
| 484 | // Otherwise, returns Error. |
| 485 | static Try<hashmap<string, string>> getBearerAuthParam( |
| 486 | const URI& uri, |
| 487 | const http::Response& response) |
| 488 | { |
| 489 | Result<http::header::WWWAuthenticate> header = |
| 490 | response.headers.get<http::header::WWWAuthenticate>(); |
| 491 | |
| 492 | if (header.isError()) { |
| 493 | return Error( |
| 494 | "Failed to get WWW-Authenticate header from " + stringify(uri) + |
| 495 | ": " + header.error()); |
| 496 | } else if (header.isNone()) { |
| 497 | return Error( |
| 498 | "Got unexpected empty WWW-Authenticate header from " + stringify(uri)); |
| 499 | } |
| 500 | |
| 501 | // According to RFC, auth scheme should be case insensitive. |
| 502 | const string authScheme = strings::upper(header->authScheme()); |
| 503 | if (authScheme == "BASIC"){ |
| 504 | return Error( |
| 505 | "Got unexpected BASIC Authorization response status: " + |
| 506 | response.status + " from " + stringify(uri)); |
| 507 | } |
| 508 | |
| 509 | if (authScheme != "BEARER") { |
| 510 | return Error( |
| 511 | "Got unsupported auth-scheme: " + authScheme + |
| 512 | " from " + stringify(uri)); |
| 513 | } |
| 514 | |
| 515 | return header->authParam(); |
| 516 | } |
| 517 | |
| 518 | |
| 519 | //------------------------------------------------------------------- |
no test coverage detected