<!--
{
  "documentType" : "article",
  "framework" : "AuthenticationServices",
  "identifier" : "/documentation/AuthenticationServices/providing-one-time-passcodes-to-autofill",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Providing one-time passcodes to AutoFill"
}
-->

# Providing one-time passcodes to AutoFill

Help people efficiently perform multifactor authentication.

## Overview

Many online services rely on one-time passcodes (OTPs), particularly time-based one-time passcodes (TOTP), as an additional factor when someone authenticates with the service.
For example, a website might ask someone to provide their username, a password which the person knows, and a TOTP generated by the person’s authenticator app to enter the site.

Your credential provider extension can supply OTPs to AutoFill so that people can automatically fill out passcodes in apps and on websites.
Someone can configure multiple credential providers in Settings so that different apps supply their passwords and OTPs in AutoFill.

### Indicate that your extension provides OTPs

Open your credential provider extension’s information property list file in Xcode and add a key to the <doc://com.apple.documentation/documentation/BundleResources/Information-Property-List/NSExtension/NSExtensionAttributes/ASCredentialProviderExtensionCapabilities> dictionary.
Set the key’s name to `ProvidesOneTimeCodes`, and its value to the Boolean `true`.

### Respond to system requests for OTP AutoFill

The system calls your credential provider view controller’s  [`provideCredentialWithoutUserInteraction(for:)`](/documentation/AuthenticationServices/ASCredentialProviderViewController/provideCredentialWithoutUserInteraction(for:)-3mo23) method with a request type of [`ASCredentialRequestType.oneTimeCode`](/documentation/AuthenticationServices/ASCredentialRequestType/oneTimeCode) to request an OTP.
If your credential provider extension can provide the code without presenting UI, call [`completeOneTimeCodeRequest(using:completionHandler:)`](/documentation/AuthenticationServices/ASCredentialProviderExtensionContext/completeOneTimeCodeRequest(using:completionHandler:)) to supply the text to the system.

Otherwise, if your credential provider extension needs to present UI to provide the OTP, call [`cancelRequest(withError:)`](/documentation/AuthenticationServices/ASCredentialProviderExtensionContext/cancelRequest(withError:)).
Use the error domain [`ASExtensionErrorDomain`](/documentation/AuthenticationServices/ASExtensionErrorDomain), and the code [`ASExtensionError.Code.userInteractionRequired`](/documentation/AuthenticationServices/ASExtensionError/Code/userInteractionRequired).
The system calls [`prepareInterfaceToProvideCredential(for:)`](/documentation/AuthenticationServices/ASCredentialProviderViewController/prepareInterfaceToProvideCredential(for:)-68qpo).
In your implementation, present the UI you need for someone to choose the OTP for the request.
Call [`completeOneTimeCodeRequest(using:completionHandler:)`](/documentation/AuthenticationServices/ASCredentialProviderExtensionContext/completeOneTimeCodeRequest(using:completionHandler:)) to supply the text to the system, or [`cancelRequest(withError:)`](/documentation/AuthenticationServices/ASCredentialProviderExtensionContext/cancelRequest(withError:)) to inform the system if an error occurs.

### Provide a list of available OTPs

When someone uses a text field to complete an OTP using AutoFill, they can tap a button to see a list of all available OTPs.
The system calls [`prepareOneTimeCodeCredentialList(for:)`](/documentation/AuthenticationServices/ASCredentialProviderViewController/prepareOneTimeCodeCredentialList(for:)) to get the list of OTPs from your extension, then presents your controller.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)