Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
AppAuth for iOS with Custom Browser

Custom Browser support for AppAuth for iOS has been implemented. Here's how to configure AppAuth to use a custom browser:

First, add the following array to your Info.plist (in XCode, right click -> Open As -> Source Code)


This is required so that AppAuth can test for the browser and open the app store if it's not installed. You only need to include the URL scheme of the browser you intend to use.

Then tweak your call to authStateByPresentingAuthorizationRequest

Change it to:

  OIDAuthorizationUICoordinatorCustomBrowser *coordinator =
      [OIDAuthorizationUICoordinatorCustomBrowser CustomBrowserChrome];
  appDelegate.currentAuthorizationFlow =
   [OIDAuthState authStateByPresentingAuthorizationRequest:request
                                                callback:^(OIDAuthState *_Nullable authState, NSError *_Nullable error) 

As you can see, with the latter code block we are creating the UI coordinator manually and using it, rather than using the default. This technique can be used with the automatic code exchange of OIDAuthState (as shown above), and manually with OIDAuthorizationService:presentAuthorizationRequest:UICoordinator:callback:.

That's it! With those two changes (which you can try on the included sample), AppAuth will use Chrome iOS for the authorization request (and open Chrome in the App Store if it's not installed).

⚠️Note: this feature is not intended for consumer apps. It is designed for advanced enterprise use-cases where the app developers have greater control over the operating environment and have special requirements that require a custom browser like Chrome.

Chrome, Firefox, Opera Mini and Safari are supported out of the box, however it's quite simple to support more browsers without changes to AppAuth, by following the patterns used for the included browsers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment