#Windows Azure Active Directory Native Client for iOS (iPhone/iPad)
This sample shows how to build an iOS application that calls a web API that requires Azure AD for authentication. This sample uses the Active Directory authentication library for iOS to do the OAuth 2.0 authorization code flow with public client.
Getting started with the sample is easy. It is configured to run out of the box with minimal setup.
To use this sample you will need a Windows Azure Active Directory Tenant. If you're not sure what a tenant is or how you would get one, read What is a Windows Azure AD tenant? or Sign up for Windows Azure as an organization. These docs should get you started on your way to using Windows Azure AD.
After you get your Windows Azure AD tenant, add this sample app to your tenant so you can use it to protect your API endpoints. If you need help with this step, see: Register the REST API Service Windows Azure Active Directory
This sample is written specifically to work against our existing sample for building a single tenant ToDo REST API for Windows Azure Active Directory. This is a pre-requisite for the Quick Start.
For information on how to set this up, visit our existing samples here:
- Windows Azure Active Directory Sample REST API Service for Node.js
- Windows Azure Active Directory Sample Web API Single Sign-On for .Net
$ git clone [email protected]:AzureADSamples/NativeClientCallWebAPISingleOrg-iOS-Dev.git
git clone [email protected]:MSOpenTech/azure-activedirectory-library-for-ios.git
In XCode, right mouse click on your project directory and select "Add files to iOS Sample"...
When you are prompted, select the directory where you cloned ADAL for iOS
Click the add button under "Linked Frameworks and Libraries" and add the library file from the imported frameworks.
Build the project to make sure everything compiles correctly.
Under "Supporting Files"you will find a settings.plist file. It contains the following information:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>authority</key>
<string>https://login.windows.net/common/oauth2/token</string>
<key>clientId</key>
<string>xxxxxxx-xxxxxx-xxxxxxx-xxxxxxx</string>
<key>resourceString</key>
<string>https://localhost/todolistservice</string>
<key>redirectUri</key>
<string>http://demo_todolist_app</string>
<key>userId</key>
<string>[email protected]</string>
<key>taskWebAPI</key>
<string>https://localhost/api/todolist/</string>
</dict>
</plist>
Replace the information in the plist file with your Web API settings.
The current defaults are set up to work with our Windows Azure Active Directory Sample REST API Service for Node.js. You will need to specify the clientID of your Web API, however. If you are running your own API, you will need to update the endpoints as required.
You should be able to connect to the REST API endpoint and be prompted with the credentials from your Windows Azure Active Directory account.