Edit

Share via


Sign in users in sample macOS app by using native authentication

Applies to: White circle with a gray X symbol. Workforce tenants Green circle with a white check mark symbol. External tenants (learn more)

This guide shows how to run an macOS sample application that demonstrates sign-up and sign in scenarios using Microsoft Entra External ID.

In this article, you learn how to:

  • Enable public client and native authentication flows.
  • Update a sample native macOS application to use your own external tenant details.
  • Run and test the sample native macOS application.

Prerequisites

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:

  1. From the app registrations page, select the app registration for which you want to enable public client and native authentication flows.
  2. Under Manage, select Authentication.
  3. Under Advanced settings, allow public client flows:
    1. For Enable the following mobile and desktop flows select Yes.
    2. For Enable native authentication, select Yes.
  4. Select Save button.

Clone sample macOS application

  1. Open Terminal and navigate to a directory where you want to keep the code.

  2. Clone the macOS application from GitHub by running the following command:

    git clone https://github.com/Azure-Samples/ms-identity-ciam-native-auth-macos-sample.git
    
  3. Navigate to the directory where the repo was cloned:

    cd ms-identity-ciam-native-auth-macos-sample
    

Configure the sample macOS application

  1. In Xcode, open NativeAuthSampleAppMacOS.xcodeproj project.

  2. Open NativeAuthSampleAppMacOS/Configuration.swift file.

  3. 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 is contoso.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 macOS 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.

Screenshot of user prompt to enter email and password in macOS app.

This guide tests Email and password usage. Enter a valid email address and password, select Sign Up, and launch the submit code screen:

Screenshot of user prompt to enter one-time passcode (OTP) in macOS app.

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.

Next steps