Get up and running in minutes

Getting Started: iOS

The following steps allow you to quickly sign in users to your application using their work or school accounts.

We built this sample using Xcode 7.3.1 on OS X El Capitan.

1. Register an app to get a client ID

Register your app to get a client ID and access a personalized version of these instructions. If you already have a client ID for an app with the implicit flow enabled you can skip to the next step.

Register your app

2. Set up the SDK

Git clone the latest version of the AAD Authentication library “ADAL” to your local machine using the following command in your terminal:

            
            

Open your existing project for which you want to integrate the sign in flow, or alternatively, create a new project.

Go to the ADAL subfolder in this git repo, and drag ADAL.xcodeproj into your project.

Select your project and then select the Build Phases tab. Expand 'Link Binary With Libraries' and add the ADAL framework by clicking the Add (+) link.

3. Add sign in logic

Copy and paste the following imports into your view controller where you would like to add the sign in flow.

The Swift code snippets are written in Swift 2. To migrate them to Swift 3, you will need to make some changes.


                

            

In the same file, copy and paste the following configurations. Then set the value of the CLIENT_ID and REDIRECT_URI variables to your application's corresponding values.


                

            

In the same file, copy and paste the following method.


                

            

4. Add a button for sign in

Replace the viewDidLoad method in your view controller with the following snippet of code. If this method does not exist, simply copy and paste the following method into your view controllers file.


                

            

5. Try it out

Build and run your application. Then click the button to launch a browser window that will authenticate the user. After completing authentication, the SDK will provide you with information about the user who authenticated based on the contents of the token provided by Microsoft.

In order to test your application, you will need at least one work account (such as an Office 365 Subscription or Azure Active Directory user account). You can learn how to create one here.

At this point the token has not been validated.  The token must be validated before you can use it to access services or data that you control.

Next Steps: Securing your Web API

Call your application’s backend service/API to validate the token and authenticate users to your backend service. Learn more here