/auth0-swiftui-login-video

Starter and completed projects to accompany the tutorial video “Integrating Auth0 within a SwiftUI App”

Primary LanguageSwiftApache License 2.0Apache-2.0

Companion projects for the video Integrating Auth0 within a SwiftUI App

Project Description

Demo app’s “Logged out” screen.   Demo app’s “Logged in” screen.

This repository contains bot the starter and completed versions of the project featured in the Auth0 video Integrating Auth0 within a SwiftUI App. The video walks the viewer through the process of adding Auth0 authentication to an iOS app based on the SwiftUI framework.

The resulting app is simple, with two screens. The first is the “Logged out” screen, which appears when the app is launched:

Demo app’s “Logged out” screen.

Tapping the Log in button starts the login process, which is handled by Auth0. The app delegates login to Auth0, which opens its web-based Universal Login page, shown below:

If the user provides valid login credentials, they are taken to the app’s “Logged in” screen:

Demo app’s “Logged in” screen.

This screen displays the following information gathered from the user’s profile:

  1. The user’s photo
  2. The user’s name
  3. The user’s email address

Tapping the Log out button logs the user out and returns them to the initial “Logged out” screen.

Getting Started

Prerequisites

  • As an iOS project, it needs to be built on a computer running macOS, preferably macOS 11.6, a.k.a. “Big Sur” or later.
  • The project is built using Apple’s official IDE, Xcode (preferably version 12 or later), which is available for download via the macOS App Store or from the Apple Developer site.
  • You’ll need an iOS device, either real or virtual:
    • If you want to deploy the app to a real iOS device, you’ll need a free Apple Developer account, which requires an Apple ID with two-factor authentication enabled.
    • If you want to deploy the app to a virtual iOS device, you just need Xcode, which includes the Simulator (which simulates current iOS devices and operating systems), as well as a facility for downloading simulators for older iOS devices and operating systems.

Installing and running the app

  1. If you don’t already have an Auth0 account, sign up for a free one.

  2. Clone the repo: git clone https://github.com/auth0-blog/get-started-ios-authentication-swiftui.git

  3. Install the Auth0.swift package using Xcode:

    • In Xcode, select FileAdd Packages.... The Add Packages window will appear.
    • In Add Packages window, enter this URL into the search field: https://github.com/auth0/Auth0.swift.git.
    • Select the Auth0.swift package that appears in the list of packages and in the Dependency Rule menu, select Up to Next Major Version.
    • Click Add Package.
  4. Log into the Auth0 dashboard, select ApplicationsApplications, and register the app. The article covers this step in detail.

  5. Once you have registered the app, copy these values from the app’s Settings page in the Auth0 dashboard:

    • Domain
    • Client ID
  6. In Xcode, open the Auth0 property list and paste the Domain ID and Client ID into the appropriate fields.

  7. Select a device from Xcode’s device menu (near the center top of its window) and click the Run button:

Selecting a device and running the app from Xcode

Additional Reading

License

The code in this repository is licensed under the Apache 2.0 License.