Passkeys
WebAuthn answered by Chromium, by your app from its own store, or refused.
import CefPasskeys
let passkeys = CefPasskeyController(policy: .app(CefKeychainPasskeyStore()))
var pageConfiguration = CefPage.Configuration()
pageConfiguration.attachments.append(passkeys)
Gallery: PasskeysDemo.
Browser example: Features/Passkeys answers passkeys with Chromium or itself, and lists saved ones in Settings.
Passkeys
Chromium answers a page’s WebAuthn calls, navigator.credentials.create()
and .get(), with its own dialog and authenticators. The optional
CefPasskeys library (.product(name: "CefPasskeys", package: "CefSwift"))
answers them instead: attach a CefPasskeyController to the page’s
configuration (attachments) with one of two policies.
| Who answers | How |
|---|---|
| Chromium, with its own dialog and authenticators | No controller, the default. |
Your app, from a CefPasskeyStore, through the controller’s delegate. Chromium’s dialog and authenticators are not used. |
CefPasskeyController(policy: .app(store)) |
Nobody: every call rejects with NotAllowedError. |
CefPasskeyController(policy: .disabled) |
import CefPasskeys
let passkeys = CefPasskeyController(policy: .app(CefKeychainPasskeyStore()))
var pageConfiguration = CefPage.Configuration()
pageConfiguration.attachments.append(passkeys)
One controller serves every page it is attached to, and a page’s popups get it with their opener’s configuration.
A controller takes the calls over through the DevTools Protocol, with a debugger that stops each document as it starts, and a page can observe that a debugger is attached (Compatibility with bot protection). Use one for pages that show your own or trusted content.
The controller sets each page up before its first document, so a
popup, tab or window the delegate lets Chromium open (.allowNativePopup)
opens in a page CefKit creates instead, with the calls taken over from
its first document; the page cannot script it
(attachments). A sign-in flow that posts its result back
to the opener needs Chromium’s passkeys: no controller.
Without a controller, what Chromium can offer depends on how the app is
signed and configured. The passkeys capability of cef bundle adds what
it can (bundling):
| Authenticator | Needs |
|---|---|
| USB and NFC security keys | Nothing. |
| A phone or tablet (QR code and Bluetooth) | NSBluetoothAlwaysUsageDescription in the app’s Info.plist and, under the hardened runtime, com.apple.security.device.bluetooth; and a launch from Finder or open, which makes the app responsible for its own Bluetooth access. |
| iCloud Keychain passkeys, through AuthenticationServices | The com.apple.developer.web-browser.public-key-credential entitlement, which Apple grants to web browsers on request, in a provisioning profile, and an Apple Development or Developer ID signature. |
| Chromium’s own profile passkeys (Touch ID) | Not available: CEF 158 checks for a keychain access group without a team prefix, which no provisioning profile can authorize. |
An ad hoc signed app gets security keys and, with the Bluetooth key,
phones. CefRuntime.shared.capabilities.webAuthnAuthenticators lists what the running app gets. Chromium shows its dialog
(“Use your security key with example.com”) as a window attached to a
CefWindow, or as a free-standing window for a CefWebView.
With .app(store), the controller’s delegate, a CefPasskeyDelegate
it holds weakly, decides each call while the page waits at it:
import CefPasskeys
final class PasskeyPolicy: CefPasskeyDelegate {
func page(_ page: CefPage, decidePasskeyFor request: CefPasskeyRequest) async -> CefPasskeyDecision {
guard request.hasUserGesture else { return .ignore } // conditional requests wait
switch request.kind {
case .registration:
return await confirm("Save a passkey for \(request.host)?") ? .createPasskey : .deny
case .assertion:
guard let passkey = await choose(from: request.passkeys) else { return .deny }
return .signIn(with: passkey)
}
}
}
CefPasskeyRequesthaskind,origin(the calling document’s, as Chromium reports it),isMainFrame,hasUserGestureand, for an assertion,passkeys: the stored passkeys a page on that origin may use, most recently used first..createPasskeymakes a new ECDSA P-256 key pair and saves the passkey, with the account the page named, to the store..signIn(with:)signs with that passkey and saves its new sign count. Both tell the site the user was verified, so verify the user first..denyrejects the call withNotAllowedErrorat once..ignoreleaves it waiting until the page aborts it or its timeout passes, which suits conditional requests (passkeys offered in an autofill list).- The page stays stopped at its call until you answer, as it does for
alert(). JavaScript you evaluate in it meanwhile waits too. When the page navigates away or the page closes first, the task running your method is cancelled and its answer is ignored. - Without a delegate,
CefPasskeyPresenter.present(_:in:verifier:)answers: it ignores requests without a user gesture, shows a sheet naming the site (with an account menu when several passkeys fit), and verifies the user before answering. The verifier,CefUserVerifier.deviceOwnerby default, asks for Touch ID or the account password throughLAContextand returns aCefUserVerification:.verified,.failed, or.unavailable(_:)on a Mac that cannot verify its user. Only.verifiedanswers the request; anything else refuses it. Pass your ownCefUserVerifierto verify another way or to treat.unavailabledifferently, and in tests, so that no system prompt appears.
Store failures fail closed. Before it asks the delegate about a
registration, the controller calls the store’s checkAvailability() (by
default a read of passkeys()), and before an assertion it reads the usable
passkeys; if either throws, the call rejects with NotAllowedError
without asking. A save happens after Chromium has handed the page its
answer, so a save that fails cannot reject the call: the site holds a
credential whose key the store does not. Every store failure reaches
page(_:passkeyStoreDidFail:) as a CefPasskeyStoreError with its
operation (.checkAvailability, .read, .save) and, for a save, the
passkey that was not saved, so the app can keep it another way or tell
the user; the default logs it.
CefPasskey holds the credential ID, relyingPartyID, userHandle,
userName, userDisplayName, the PKCS #8 privateKey, signCount and
dates. List and remove passkeys through the store, for a settings screen:
import CefPasskeys
let store = CefKeychainPasskeyStore()
let saved = try await store.passkeys()
try await store.remove(saved[0])
| Store | Keeps passkeys |
|---|---|
CefInMemoryPasskeyStore |
In memory, until it is released. For tests and private browsing. |
CefKeychainPasskeyStore(service:accessGroup:) |
In the data protection keychain, one item per passkey, available while the Mac is unlocked and never synced. Needs a team signature with a provisioning profile, which gives the app the com.apple.application-identifier entitlement the data protection keychain checks; an ad hoc signed app gets errSecMissingEntitlement (-34018) as CefError.operationFailed. It never shows a keychain password prompt. |
Adopt CefPasskeyStore (passkeys(), save(_:), remove(_:), and
optionally checkAvailability()) to keep them elsewhere, such as in a
password manager.
Chrome’s settings link to Chromium’s password manager from Autofill and
passwords → Passkeys. That tab arrives through
onChromeTab like the other
password-manager links.
The Browser example has a Passkeys setting (Chromium or the browser
itself, through a CefPasskeyController) and lists and removes saved
passkeys in its Settings window (Features/Passkeys/Passkeys.swift).
Passkeys
A CefPasskeyController (CefPasskeys) is an attachment that prepares
before the first document. For each page it is attached to, a
CefPasskeySession takes the WebAuthn calls over through the page’s
DevTools connection, before the page loads its first document:
WebAuthn.enable, without Chromium’s UI, puts the page’s documents in a virtual authenticator environment. Chromium’s dialog and its real authenticators (security keys, iCloud Keychain, phones) are not used there, and a call waits for an authenticator until its timeout.- Each document’s main-world context gets a function-call breakpoint
(
Debugger.setBreakpointOnFunctionCall) on itsCredentialsContainer.prototype.createand.getbefore any of its scripts runs.Page.addScriptToEvaluateOnNewDocumentruns a script of one statement,debugger, at the start of every document in an isolated world namedcefswift-passkeys, which the page cannot see or reach. The renderer stops there. The document’s main-world context has been reported by then, andRuntime.evaluatein that context works while the renderer is stopped, so the breakpoints are set before the page’s first script. (Setting them whenRuntime.executionContextCreatedarrives, without the stop, loses to a script that calls at once.) - A call stops the page before the call runs, in the caller’s frame; the
frame’s script gives the execution context, which gives the origin and
frame.
navigator.userActivation.isActiveis read in that frame withthrowOnSideEffect, so the read cannot change the page. Nothing in the page is changed. Any other pause, such as adebuggerstatement in the page, is resumed at once unless someone else debugs the page: the app, holding its ownDebugger.enablelease on the page’s session, or the page’s DevTools window. Those pauses are theirs to resume. - While the page is stopped, the delegate decides, and the session adds a
virtual authenticator (CTAP 2.1, internal transport, resident keys,
user verification) for that one call: empty for a registration, holding
only the chosen passkey (its PKCS #8 key from the store) for an
assertion, or with failing user verification for a refusal, which
rejects the call at once. The page then resumes and makes its call.
WebAuthn.credentialAddedorcredentialAssertedreports the result, which goes to the store, and the authenticator is removed. Chromium reports the credential as it answers the page, so the save cannot change the page’s result; the store is checked before the delegate is asked instead (checkAvailability()for a registration, the read of usable passkeys for an assertion), and a failure there refuses the call. An authenticator left over from an earlier call is removed before the next decision, so no call is answered unasked.
An Alloy page discarded by closing it gets a new DevTools session when
it is created again, so the controller sets the environment and the
breakpoints up again in pageDidRestore(_:); a Chrome-style tab
discarded in place keeps them.
The private key of a passkey lives in the store, and in Chromium’s browser process only while an authenticator answers one call. A page learns only what WebAuthn gives it: the credential ID, the public key, the user handle and signatures.
Chromium’s own WebAuthn dialog (a page without a controller) is a views widget: a child
window of a CefWindow, or a free-standing window for a page in
a view. CefSwift leaves it alone; closing it from AppKit crashes Chromium.
The iCloud Keychain authenticator in Chromium (device/fido/mac) calls
AuthenticationServices itself and checks for the
com.apple.developer.web-browser.public-key-credential entitlement;
without it, Chromium does not offer it.
Passkeys: a module on an attachment, not a CefKit option
App-answered passkeys used to be CefPage.Configuration.passkeys, with
passkey members on CefPageDelegate and a passkey case in CefKit’s
popup handling. They do not need CefKit’s internals beyond a DevTools
session that is in place before the first document, so they moved to the
optional CefPasskeys module, built on CefPageAttachment. What made
passkeys special in CefKit, holding the first document and refusing to
let Chromium create native popups, became one general property an
attachment declares (preparesBeforeFirstDocument): any attachment that
must see every document from its first script needs both. A page with
no such attachment keeps native popups and starts on its page at once.