Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to: External tenants (learn more)
In this quickstart you learn how to run an iOS sample application that demonstrates sign-up, sign in, sign out, and reset password scenarios using Microsoft Entra External ID.
Prerequisites
An Azure account with an active subscription. If you don't already have one, Create an account for free
This Azure account must have permissions to manage applications. Any of the following Microsoft Entra roles include the required permissions:
- Application Administrator
- Application Developer
An external tenant. If you don't have one, create a new external tenant in the Microsoft Entra admin center.
If you haven't already done so, Register an application in the Microsoft Entra admin center. Make sure to:
- Record the Application (client) ID and Directory (tenant) ID for later use.
- Grant admin consent to the application.
If you haven't already done so, Create a user flow in the Microsoft Entra admin center
Enable public client and native authentication flows
To specify that this app is a public client and can use native authentication, enable public client and native authentication flows:
- From the app registrations page, select the app registration for which you want to enable public client and native authentication flows.
- Under Manage, select Authentication.
- Under Advanced settings, allow public client flows:
- For Enable the following mobile and desktop flows select Yes.
- For Enable native authentication, select Yes.
- Select Save button.
Clone sample iOS mobile application
Open Terminal and navigate to a directory where you want to keep the code.
Clone the iOS mobile application from GitHub by running the following command:
git clone https://github.com/Azure-Samples/ms-identity-ciam-native-auth-ios-sample.git
Navigate to the directory where the repo was cloned:
cd ms-identity-ciam-native-auth-ios-sample
Configure the sample iOS mobile application
In Xcode, open NativeAuthSampleApp.xcodeproj project.
Open NativeAuthSampleApp/Configuration.swift file.
Find the placeholder:
Enter_the_Application_Id_Here
and replace it with the Application (client) ID of the app you registered earlier.Enter_the_Tenant_Subdomain_Here
and replace it with the Directory (tenant) subdomain. For example, if your tenant primary ___domain iscontoso.onmicrosoft.com
, use contoso. If you don't have your tenant subdomain, learn how to read your tenant details.
Note
Remember to select a scheme to build and destination where you run the built products. Each scheme contains a list of real or simulated devices that represent the available destinations.
Run and test sample iOS mobile application
To build and run your code, select Run from the Product menu in Xcode. After a successful build, Xcode will launch the sample app in the Simulator.
This guide tests Email one-time-passcode usage. Enter a valid email address, select Sign Up, and launch the submit code screen:
After you enter your email address on the previous screen, the application will send a verification code to it. Once you submit the received code, the application takes you back to the previous screen and automatically signs you in.
Other scenarios that this sample supports
The sample app supports the following flows:
- Email + password covers sign-in or sign-up flows with an email with password.
- Email + password sign-up with user attributes covers sign-up with email and password, and submitting user attributes.
- Password reset covers self-service password reset (SSPR).
- Access Protected API covers call a protected API after the user successfully signs up or signs in and acquires an access token.
- Fallback to web browser covers the use the browser-based authentication as a fallback mechanism when the user can't complete authentication through native authentication for whatever reason.
Test email with password flow
In this section, you test email with password flow, with its variants such as, email with password sign-up with user attributes and SSPR:
Use the steps in create a user flow to create a new user flow, but this time select Email with password as your authentication method. You need to configure Country/Region and City as the user attributes. Alternatively, you can modify the existing user flow to use Email with password (Select External Identities > User flows > SignInSignUpSample > Identity providers > Email with password > Save).
Use the steps in associate the application with the new user flow to add an app to your new user flow.
Run the sample app, then select the ellipsis menu (...) to open more options.
Select the scenario you want to test, such as Email + password or Email + password sign-up with user attributes or Password reset, then follow the prompts. To test Password reset, you need to first sign up a user, and enable email one-time passcode for all users in your tenant.
Test call a protected API flow
Use the steps in Call a protected web API in a sample iOS mobile app by using native authentication to call a protected web API from a sample Android mobile app.