<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "visionOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AuthenticationServices",
  "identifier" : "/documentation/AuthenticationServices/ASCredentialProviderViewController/prepareOneTimeCodeCredentialList(for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Authentication Services"
    ],
    "preciseIdentifier" : "c:objc(cs)ASCredentialProviderViewController(im)prepareOneTimeCodeCredentialListForServiceIdentifiers:"
  },
  "title" : "prepareOneTimeCodeCredentialList(for:)"
}
-->

# prepareOneTimeCodeCredentialList(for:)

Prepares the interface to display a list of one-time passcodes (OTPs) that people can select from.

```
func prepareOneTimeCodeCredentialList(for serviceIdentifiers: [ASCredentialServiceIdentifier])
```

## Parameters

`serviceIdentifiers`

An array of service identifiers that provide a hint about the service that people need an OTP for.

## Overview

## Discussion

The system calls this method to tell your extension’s view controller to prepare a list of OTPs to present. After calling this method, the system presents the view controller to the person.

Use the given `serviceIdentifiers` array to filter or prioritize the credentials to display. The service identifier array might be empty, but your extension still shows credentials that the person can select from.

Items in the array with lower indices represent more specific identifiers for which an OTP’s requested. For example, if the array contains identifiers `[m.example.com, example.com]`, the item `m.example.com` represents the more specific service that requires an OTP.

When someone selects an OTP displayed by your view controller, represent the passcode as an [`ASOneTimeCodeCredential`](/documentation/AuthenticationServices/ASOneTimeCodeCredential) and pass it to the system by calling [`completeOneTimeCodeRequest(using:completionHandler:)`](/documentation/AuthenticationServices/ASCredentialProviderExtensionContext/completeOneTimeCodeRequest(using:completionHandler:)):

```swift
let credential = ASOneTimeCodeCredential(code: otpCode)
await extensionContext.completeOneTimeCodeRequest(using: credential)
```

Always provide a way for someone to cancel the operation from your view controller, for example, by including a Cancel button in the navigation bar.
When someone cancels the operation, call [`cancelRequest(withError:)`](/documentation/AuthenticationServices/ASCredentialProviderExtensionContext/cancelRequest(withError:)), using the error domain [`ASExtensionErrorDomain`](/documentation/AuthenticationServices/ASExtensionErrorDomain) and code [`userCanceled`](/documentation/AuthenticationServices/ASExtensionError/userCanceled):

```swift
let error = NSError(domain: ASExtensionErrorDomain,
                    code: ASExtensionError.userCanceled.rawValue)
extensionContext.cancelRequest(withError: error)
```

The system dismisses your view controller after you call either the completion or cancellation method.

---

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)