This is an unofficial port of the 1Password Extension by AgileBits to Swift
Welcome! With just a few lines of code, your app can add 1Password support, enabling your users to:
- Access their 1Password Logins to automatically fill your login page.
- Use the Strong Password Generator to create unique passwords during registration, and save the new Login within 1Password.
- Quickly fill 1Password Logins, Credit Cards and Identities directly into web views.
Empowering your users to use strong, unique passwords has never been easier. Let's get started!
This Swift port is currently under development!
github "SomeKindOfCode/onepassword-app-extension" "feature/swift"
Currently not available
Swift Version: 4.0
Implementations:
- Find Login (e.g. to fill In-App Form)
- Fill Form inside WebView (UIWebView and WKWebView supported)
- Store Login
- Change Password
These managers have been tested to support the generic protocol to return at least a selected login:
- 1Password
- LastPass
- Enpass
- Dashlane
Coming (soon):
- RememBear
Use this to let the user pick a login by domain and fill a custom form inside your app
OnePasswordExtention.findLogin(urlString: "https://www.acme.com", viewController: self, sender: sender) { (loginDictionary, error) in
self.usernameTextField.text = loginDictionary?[onepass: .username]
self.passwordTextField.text = loginDictionary?[onepass: .password]
}
You can use the extension to help the user log into a website you embedded inside either a UIWebView
or a WKWebView
OnePasswordExtention.fillItemInto(webView: self.webView, for: self, sender: sender, showOnlyLogins: false) { (success, error) in
if !success {
print("Failed to fill into webview: <\(String(describing: error))>")
}
}
Note that when you use SFWebViewController
, you will give the user regular access to the regular action via the share button as the user is familiar with by using Safari.
As you maybe noted, there are a few helper implemented for you to make life a little easier.
The loginDictionary
objects, returned from methods like findLogin
have a custom subscript that accepts the Constants.Keys
enum. This should help you find the values you are looking for.
There is also a OnePasswordError
enum that helps you identify different errors that could happen while using the Framework.
As we don't know if there will be another successor to the WKWebView
, there is a protocol named WebViewCompatible
[^1 ] so this can be added to any successor or custom WebView implementations[^2].
- Don't forget that since iOS 11, the user can use his iCloud Keychain to fill logins.
- Set the content types of your form fields correctly (either in code or in the Interface Builder)
- Get more information about "AutoFill for Apps" at Session 206 of WWDC17
- Use the same
URLString
during Registration and Login. - Ensure your
URLString
is set to your actual service so your users can easily find their logins within the main 1Password app. - You should only ask for the login information of your own service or one specific to your app. Giving a URL for a service which you do not own or support may seriously break the customer's trust in your service/app.
- If you don't have a website for your app you should specify your bundle identifier as the
URLString
, like so:app://bundleIdentifier
(e.g.app://com.acme.awesome-app
). - Use the icons provided in the
1Password.xcassets
asset catalog so users are familiar with what it will do. Contact us if you'd like additional sizes or have other special requirements. - On your registration page, pre-validate fields before calling 1Password. For example, display a message if the username is not available so the user can fix it before calling the 1Password extension.
If you open up OnePasswordExtension.m and start poking around, you'll be interested in these references.
- Apple Extension Guide
- NSItemProvider, NSExtensionItem, and UIActivityViewController class references.
[^1 ]: The extension made UIWebView and WKWebView conform to this protocol to save some lines of code
[^2 ]: Are there any Chrome-/FireFox-/Edge-WebViews?