Safe Rust bindings for Apple's AuthenticationServices framework on macOS.
Status: Sign in with Apple, password, passkey and security-key requests,
ASAuthorizationController,ASWebAuthenticationSession,ASCredentialIdentityStoreandASSettingsHelpercall into the framework through the Swift bridge. The provider-extension / Platform SSO, single sign-on, credential-provider and web-browser families are Rust-side data models that make no framework calls; seeCOVERAGE.md.
[dependencies]
authenticationservices-rs = "0.5"The library is imported as authenticationservices. The optional async feature adds executor-agnostic futures for ASAuthorizationController and ASWebAuthenticationSession.
The default full feature gives the complete API. It adds the base64, serde, serde_json and zeroize dependencies. If your app uses only ASWebAuthenticationSession, set default-features = false:
[dependencies]
authenticationservices-rs = { version = "0.5", default-features = false, features = ["async"] }Without full, the only dependency is doom-fish-utils, and the crate contains these items:
WebAuthenticationSession,WebAuthenticationSessionGuard,WebAuthenticationCallbackandWebAuthenticationSessionInfo.AuthenticationServicesErrorand the four*_error_domainfunctions.SettingsHelperand theAppleIdButtontypes.- With the
asyncfeature,AsyncWebAuthenticationSessionandWebAuthenticationSessionFuture.AsyncAuthorizationControlleris available only withfull.
- macOS 12 or newer (the Swift bridge's deployment target) and Rust 1.82 or newer.
- Newer APIs are checked at run time and return
AuthenticationServicesError::NotSupportedon older systems:ASAuthorizationControllerrequest options need macOS 13,client_dataneeds macOS 13.5 for passkeys and macOS 14.4 for security keys, passkey credential identities need macOS 14, listing credential identities and HTTPS web-session callbacks need macOS 14.4, the security-keyappIDneeds macOS 14.5, one-time-code credential identities and the passkeyrequestStyleneed macOS 15, and app service identifiers and display names on credential identities need macOS 26.2. - Cancelling an authorization controller needs macOS 13; on macOS 12
AuthorizationGuard::cancelreturnsNotSupported. Large-blob inputs need macOS 14 and PRF inputs macOS 15; on older systems a request that sets them returnsNotSupported, and the matching outputs areNone.
- Passkey requests need an associated-domains
webcredentials:entry for the relying party, and Sign in with Apple needs the Sign in with Apple capability. - Performing requests created from
client_datais meant for web browsers and needs the web-browser public-key-credential entitlement. - Saving, replacing or removing credential identities needs an app with a credential provider extension that the user has enabled. Otherwise the framework's error is returned as
AuthenticationServicesError::FrameworkError.
- Every passkey and security-key request needs a non-empty challenge, either directly or inside
client_data; a missing or empty one is anInvalidArgumenterror. The challenge and client data are fixed when a request is created, so create a new request for each ceremony. Registrations also need a user ID of 1 to 64 bytes. Debugoutput redacts identity tokens, authorization codes, passwords, signatures, passkey user IDs, PRF outputs and large-blob data, and in the Rust-side models also SSO tokens, private keys, HPKE pre-shared keys, authorization header values, HTTP bodies and one-time codes.- Identity tokens, authorization codes, passwords, PRF outputs and large-blob data are
zeroize::Zeroizingvalues that are wiped on drop and compared in constant time. The copiesAuthenticationServiceskeeps cannot be wiped from Rust. AuthorizationGuardandWebAuthenticationSessionGuardown their callback context. Dropping a guard cancels the flow, and callbacks that arrive afterwards are ignored.- Every bridge call checks the class of the handle it is given and returns
InvalidArgumentfor a mismatch. - Request handles are
Sendbut notSync.updateapplies the whole configuration, so start fromconfiguration(): it changes the user ID, name and display name, and clears inputs left asNoneor empty. It returnsInvalidArgumentwhile an authorization controller still holds the request. - The framework runs authorization and web-authentication flows on the main thread, so the host must run its main run loop.
WebAuthenticationSession::startand the asyncstartmust be called on the main thread and returnMainThreadRequiredelsewhere.
use authenticationservices::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("provider protocol: {}", authorization_provider_protocol_name()?);
let store = CredentialIdentityStore::shared();
println!("credential identity store supported: {}", CredentialIdentityStore::is_supported());
println!("credential identity store state: {:?}", store.state()?);
Ok(())
}AppleIdProvider,AppleIdRequest,AppleIdRequestConfiguration— Sign in with Apple request construction and credential-state queries.PasswordProvider,PasswordRequest,PasswordCredential— keychain-password request and credential helpers.PlatformPublicKeyCredentialProviderandSecurityKeyPublicKeyCredentialProvider— passkey and security-key registration/assertion request builders.AuthorizationController,AuthorizationGuard,Authorization—ASAuthorizationControllerorchestration and typed credential decoding.WebAuthenticationSession,WebAuthenticationCallback—ASWebAuthenticationSessionbuilders and callback matching helpers.CredentialIdentityStoreand credential identity models —ASCredentialIdentityStorestate, save/replace/remove/remove-all, and listing of password, passkey and one-time-code identities.SettingsHelper— wrappers for theASSettingsHelperstatic helpers.AppleIdButton,UserDetectionStatus,UserAgeRange, andauthorization_*_error_domainhelpers — Apple ID UI helpers plus shared authorization metadata.ProviderExtension*,SingleSignOn*,CredentialProvider*, andWebBrowser*wrappers — Rust-side models for Platform SSO, SSO credentials, credential-provider/passkey extension flows, and browser-mediated passkey requests.accountandAccountAuthenticationModificationControllerplaceholders — explicit macOSNotSupportedcoverage for APIs that are unavailable in the macOS SDK.
cargo run --example 01_authenticationservices_smokecargo run --example 02_apple_id_providercargo run --example 03_authorization_providercargo run --example 04_password_credentialcargo run --example 05_authorization_controller_resultcargo run --example 06_passkeyscargo run --example 07_web_authentication_sessioncargo run --example 08_credential_identity_storecargo run --example 09_account_requestscargo run --example 10_account_authentication_modification_controllercargo run --example 11_settings_helpercargo run --example 12_async_authorization_controller --features async
- See
COVERAGE.mdfor the per-area matrix. ASAccountAuthenticationModification*is not available in the macOSAuthenticationServicesSDK, so this crate exposes explicit placeholder types that returnAuthenticationServicesError::NotSupportedon macOS.ASCredentialIdentityStorestate, mutation and listing are bridged to the framework; see Requirements and Entitlements above.- The Platform SSO
OpenIDand token-exchange additions in the macOS 27 SDK are not covered. - Some newer
AuthenticationServicesfeatures remain gated by macOS availability (for example HTTPS callback matching inASWebAuthenticationSession.Callback, large-blob and PRF details for passkeys, and the newestASSettingsHelperentry points).
Licensed under either of Apache-2.0 or MIT at your option.