CefAuthCallback
Header: cef_auth_callback.h
Category: System Utilities
Overview
Tasks, threads, parsers, streams, cookies, URL requests, scheme registration, and constant tables.
CefAuthCallback
Source File: include/cef_auth_callback.h
Process / Thread Context: Browser Process / IO Thread (returned to the client from CefURLRequestClient::GetAuthCredentials and CefRequestHandler::GetAuthCredentials, which are documented as called on the IO thread for URL requests; this object is then used on that same thread).
Purpose: Callback interface used for asynchronous continuation of authentication requests. It is handed to the embedder when CEF needs HTTP authentication credentials so the embedder can supply them asynchronously (or cancel the request) instead of blocking.
Methods
void Continue(const CefString& username, const CefString& password)
Parameters:
username: The username to authenticate with. May be empty for anonymous or for some schemes.password: The password to authenticate with. May be empty.
Return Value: Returns void. Calling Continue() resumes the network request with the supplied credentials; calling it after Cancel() or after a second invocation is undefined.
Usage Instruction: Call this when you have collected credentials from the user (e.g. from a dialog). It must be called exactly once per CefAuthCallback instance, either Continue() or Cancel(). Per the optional_param=username,optional_param=password translator tag both parameters are optional on the C-API side; the C++ signature still requires both CefString arguments but they may be empty.
Threading Constraint: Threading constraint not specified in header; in practice the callback is invoked on the thread that received it (typically the IO thread).
void Cancel()
Parameters:
- None.
Return Value: Returns void. Cancels the pending authentication, which fails the originating request.
Usage Instruction: Call when the user declines to authenticate or when the embedder cannot supply credentials. Calling Cancel() more than once, or after Continue(), is undefined.
Threading Constraint: Threading constraint not specified in header.
Usage Example
// Inside a CefURLRequestClient implementation — asynchronous credential
// retrieval from a UI dialog (which runs on the UI thread).
class MyURLRequestClient : public CefURLRequestClient {
bool GetAuthCredentials(bool isProxy,
const CefString& host,
int port,
const CefString& realm,
const CefString& scheme,
CefRefPtr<CefAuthCallback> callback) override {
// Show a dialog on the UI thread, then call back into `callback`.
ShowLoginDialog(host, realm, [callback](const std::string& u,
const std::string& p) {
if (u.empty() && p.empty())
callback->Cancel();
else
callback->Continue(u, p);
});
return true; // We have taken ownership of the callback.
}
// ... other CefURLRequestClient methods ...
};