| 749 | } |
| 750 | |
| 751 | void JWKSMgr::UpdateJWKSThread() { |
| 752 | std::shared_ptr<JWKSSnapshot> new_jwks; |
| 753 | const MonoDelta &timeout = MonoDelta::FromSeconds(FLAGS_jwks_update_frequency_s); |
| 754 | |
| 755 | while (true) { |
| 756 | if (shut_down_promise_.WaitFor(timeout) != nullptr) { |
| 757 | // Shutdown has happened, stop updating JWKS. |
| 758 | break; |
| 759 | } |
| 760 | |
| 761 | new_jwks = std::make_shared<JWKSSnapshot>(); |
| 762 | bool is_changed = false; |
| 763 | Status status = |
| 764 | new_jwks->LoadKeysFromUrl(jwks_uri_, jwks_verify_server_certificate_, |
| 765 | current_jwks_checksum_, &is_changed); |
| 766 | if (!status.ok()) { |
| 767 | LOG(WARNING) << "Failed to update JWKS: " << status.ToString(); |
| 768 | } else if (is_changed) { |
| 769 | SetJWKSSnapshot(new_jwks); |
| 770 | if (new_jwks->IsEmpty()) { |
| 771 | LOG(WARNING) << "New JWKS snapshot is empty."; |
| 772 | } |
| 773 | } |
| 774 | new_jwks.reset(); |
| 775 | } |
| 776 | // The promise must be set to true. |
| 777 | DCHECK(shut_down_promise_.Get()); |
| 778 | } |
| 779 | |
| 780 | JWKSSnapshotPtr JWKSMgr::GetJWKSSnapshot() const { |
| 781 | std::lock_guard<std::mutex> l(current_jwks_lock_); |