UIActivityViewController, and the person picks 1Password.
The action extension is available in 1Password for iOS 8.12.42 or later. See Supported builds.
How it works
- Your app wraps the access request reference in an
OnePasswordAccessRequest, encodes it as JSON, and attaches it to anNSExtensionItemascom.1password.access-request. - Your app presents a
UIActivityViewControllerwith that item, and the person picks 1Password. - 1Password shows the access request, unlocking first if needed, and the person grants or declines it.
- Your app’s
completionWithItemsHandlerreceives either acom.1password.access-grantattachment, which decodes to anOnePasswordAccessGrant, or an error.
Get the access request reference
Create the access request first. The reference is the value 1Password reads to find the account and the request, including what you asked for and why. It’s theaccess_request_reference value in the appLink returned when you create the request, by the browser extension’s createAccessRequest or by the SDK’s accessRequests.create. If you create requests with the SDK, contact 1Password first.
Pass the reference unchanged. Don’t decode it, edit it, or build it from parts. Like the approval link, it carries your request text, so keep it out of logs and model context.
Add the integration types
1Password provides these Swift definitions. Add them to your app target:The request
The access grant
The access grant is the access request’s status, read from 1Password after the person granted it. It matches what the SDK’saccessRequests.getStatus returns, except for reference: in the grant, each reference is an object that wraps the reference string, { "reference": "<string>" }, while getStatus returns the string itself:
A later version of this protocol is expected to return each
reference as a plain string, the same as getStatus.Declare the 1Password types
Access requests and grants use two Uniform Type Identifiers. Both conform topublic.json.
1Password owns these types, so declare them as imported types in your app’s
Info.plist:
Info.plist
UTType(importedAs:), which resolves them correctly only once your Info.plist declares them.
Send the access request
- Wrap the access request reference in an
OnePasswordAccessRequestand encode it as JSON. - Register the JSON on an
NSItemProvider, then attach the provider to anNSExtensionItem. - Create a
UIActivityViewControllerwith that item, and present it the way your app presents any share sheet.
Handle the result
UIKit callscompletionWithItemsHandler when the share sheet closes. What you receive depends on how the request ended:
Decode the access grant
Find the attachment that conforms to the access grant type, load its JSON, and decode it as anOnePasswordAccessGrant:
Use the grant
Eachreference in the grant identifies one granted login. It holds no secret, and it works only with the access token and integration key of the connection that created the request, which stay on your side. The extension and the SDK both take the string inside it, reference.reference, not the object:
- To fill in your agent’s browser: pass
reference.referenceto the extension’sfillCredentialasresourcePath, with the same connection’s access token and integration key. - To read the login with the SDK: pass
reference.referenceto the SDK’s read methods. See Read a granted login.
Errors
If the person declines, or 1Password can’t process the request, the share sheet passes you an error. These are the errors 1Password reports today, the cases ofOnePasswordAccessRequestError:
Treat any other error as a failed access request. 1Password may add error cases, and the system can pass you errors of its own.