1Password Extension for Xamarin.iOS apps

1Password is one of my favorite application on Mac and iPhone. It’s 1Password Logoworking pretty well across devices, browsers (Chrome/Safari in my cases). With one unique master password, 1Password enables different strong, complex passwords to all online socials.

There is a bunch of iOS applications on Store that use 1Password login side already, see here: https://blog.agilebits.com/1password-apps . Most of the popular apps are named here. Below are how it looks on Dropbox and Pluralsight (notice the 1Password icon?)

1Password Extension for Xamarin.iOS apps - Demo Dropbox 1Password Extension for Xamarin.iOS apps - Demo Pluralsight

 

How do we add this extension to our iOS application? There is “1Password Extension for iOS Apps” that helps iOS developers support using 1Password login inside their applications, check out https://github.com/AgileBits/onepassword-app-extension, but only for Objective-C and Swift. Well, how about Xamarin?

Xamarin.iOS Binding for 1Password Extensions

Yes, I made the bindings library for it, check this Nuget package: 1PasswordExtension for Xamarin.iOS

The source code is hosted on Github: https://github.com/trinnguyen/onepassword-app-extension-xamarin

Anyone who is curious about how it is built can look at there and built their own DLL too, it fetches the latest Release of the original Objective-C library to build CocoaTouch framework.

The binding ApiDefinitions class is generated by using Objective Sharpie with CocoaPods components, I hope to have some time to write about it later.

Integrate to 1Password to your Xamarin.iOS app

1. Install Nuget package and add assets

Simply install the Nuget package (bindings of 1Password Extension) to Xamarin.iOS project

Install-Package Xamarin.1PasswordExtension

Add 1Password.xcassets catalog to the application bundle, these images are provided by 1Password Team to help user recognize the button. This resource can be found on my Github repo or the original library

2. Add LSApplicationQueriesSchemes in Info.plist

1Password extension uses UIApplication.CanOpenURL to check whether the app extension is available, with value “org-appextension-feature-password-management“, thus any application that supports password management actions can be visible.

One iOS 9+, application need to whitelist org-appextension-feature-password-management in LSApplicationQueriesSchemes

  • Open your Info.plist file, tab Source
  • Add new row: LSApplicationQueriesSchemes (array) with item: org-appextension-feature-password-management

Play with source code

There are 4 use cases that normally integration works, for details check out document of the original library. In this article, I will show how it works on Xamarin with C# code

A demo Xamarin.iOS application is provided on my Github repo, covers 3 use cases. For webView, check below sample code.

check app Extension is available

Hide 1Password button if the App Extension is not visible (1Password app is not installed on iOS device yet)

Use Case #1: Native App Login

Use Case #2: New User Registration

Use Case #3: Change Password

Use Case #4: Web View Filling