Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
162 commits
Select commit Hold shift + click to select a range
855b96d
refactor: implementations as described in API doc
russellwheatley Oct 2, 2025
8c15371
refactor: Facebook provider
russellwheatley Oct 2, 2025
bbce389
refactor: google provider
russellwheatley Oct 2, 2025
f2609f0
refactor: phone auth provider
russellwheatley Oct 2, 2025
6fe345a
chore: rename according to API doc
russellwheatley Oct 2, 2025
0802dfa
refactor: rename login to signUp
russellwheatley Oct 2, 2025
3103a2d
chore: rm unneeded assignment
russellwheatley Oct 2, 2025
efa29b4
refactor: return `SignInOutcome` for authentication methods
russellwheatley Oct 2, 2025
5c84e32
fix: make sendEmailVerification public
russellwheatley Oct 2, 2025
b3fd259
refactor: rename API labels
russellwheatley Oct 2, 2025
04c3dce
feat: user profile update methods
russellwheatley Oct 2, 2025
2b02383
chore: remove deprecated "name" arg from packages
russellwheatley Oct 7, 2025
c7c3e4d
chore: remove preconcurrency from phone auth
russellwheatley Oct 7, 2025
9e58282
Merge pull request #1272 from firebase/refactor-api
russellwheatley Oct 7, 2025
36b1c77
feat: MFA enrolment flow
russellwheatley Oct 3, 2025
5d75816
fix: make secret internal but not private
russellwheatley Oct 3, 2025
bb34c52
feat: integrate MFA enrolment View
russellwheatley Oct 3, 2025
c5aa33a
ci: update SwiftUI CI workflow
russellwheatley Oct 3, 2025
8d9e8bc
test: unit tests for enrolment
russellwheatley Oct 3, 2025
a661857
test: integration test updates
russellwheatley Oct 3, 2025
54bb93e
test: fix UI tests
russellwheatley Oct 3, 2025
d97238b
test: remove Timer from UI tests
russellwheatley Oct 3, 2025
55f95b8
test: MFA enrolment tests
russellwheatley Oct 3, 2025
0307ebd
test: bifurcate test setup with content view + test helpers
russellwheatley Oct 3, 2025
ba2c62c
chore: clean up
russellwheatley Oct 3, 2025
0807e7c
feat: MFA management and resolution logic
russellwheatley Oct 3, 2025
1c7fed3
tests: further test setup
russellwheatley Oct 3, 2025
ca787a7
fix: back button email link
russellwheatley Oct 3, 2025
69dfd19
test: MFA resolution
russellwheatley Oct 3, 2025
da1a999
chore: clean up logs/code comments
russellwheatley Oct 3, 2025
a6b8a49
fix: catch MFA error
russellwheatley Oct 3, 2025
3c78329
chore: clean up
russellwheatley Oct 3, 2025
f4e6384
test: comment out test assertion that fails on emulator
russellwheatley Oct 6, 2025
abce28c
feat: one tap copy of TOTP secret
russellwheatley Oct 6, 2025
4763afd
fix: only show keyboard once text field has been tapped
russellwheatley Oct 6, 2025
0c88e41
fix: textfield comes into View when tapped
russellwheatley Oct 7, 2025
ce8a513
chore: previews for enrolment
russellwheatley Oct 7, 2025
c74865c
fix: ensure barcode is visible and inputs come into view when tapped
russellwheatley Oct 7, 2025
ee930ed
feat: allow opening app for creating TOTP auth
russellwheatley Oct 7, 2025
571f479
chore: display name is not optional
russellwheatley Oct 7, 2025
b7282fc
ci: update swiftui workflow + run on development branch
russellwheatley Oct 7, 2025
9c6705b
Merge pull request #1274 from firebase/update-ci-flow
russellwheatley Oct 7, 2025
0c002fc
Merge branch 'development' into mfa-enrollment
russellwheatley Oct 7, 2025
36449ce
fix: change the package.swift in line with removing deprecated names
russellwheatley Oct 7, 2025
a7682e5
tests: fix tests after UI changes
russellwheatley Oct 7, 2025
77927c8
chore: add back button and align another one to the left
russellwheatley Oct 9, 2025
3100258
chore: enhance reauth by using guard instead of if/else
russellwheatley Oct 9, 2025
bc4e84e
chore: make MFA info identifiable
russellwheatley Oct 9, 2025
a4c120d
Merge pull request #1273 from firebase/mfa-enrollment
russellwheatley Oct 9, 2025
92e1453
feat: Implement Twitter provider
russellwheatley Oct 9, 2025
819e05b
fix: twitter provider update to be pass through `withTwitterSignIn()`
russellwheatley Oct 9, 2025
c233113
fix: import twitter to allow sign-in
russellwheatley Oct 9, 2025
ef5f786
refactor: provider logic so it can be passed into button
russellwheatley Oct 10, 2025
ad137a0
fix: display name if email is unavailable, twitter sometimes user use…
russellwheatley Oct 10, 2025
4cb5f27
chore: use withTwitterSignIn() for test and content view
russellwheatley Oct 10, 2025
76e8ceb
feat: pass provider to providerWithUI
russellwheatley Oct 10, 2025
5283f65
fix: renamed arg to make it clear the distinction between provider & …
russellwheatley Oct 10, 2025
4dbd565
fix: make provider arg optional
russellwheatley Oct 10, 2025
1b6a295
feat: implement API for deleting Twitter user
russellwheatley Oct 10, 2025
7a37a33
fix: put delete function on the provider
russellwheatley Oct 10, 2025
ac7f146
format
russellwheatley Oct 10, 2025
94415ff
feat: Twitter sign-in button styling
russellwheatley Oct 10, 2025
cab823c
chore: change button name to "X"
russellwheatley Oct 10, 2025
854a506
test: sign in buttons are visible on auth picker
russellwheatley Oct 10, 2025
d1602f8
fix: sometimes email isn't available so use `as:` instead
russellwheatley Oct 10, 2025
4897996
fix: remove incorrect naming
russellwheatley Oct 10, 2025
855e40b
test: pass emulator argument
russellwheatley Oct 20, 2025
5259847
test: test setup should be from tests
russellwheatley Oct 20, 2025
a643720
test: refactor tests so setup occurs before running test runner
russellwheatley Oct 20, 2025
9c2255e
test: create test app function
russellwheatley Oct 20, 2025
d3d1f7b
test: remove duplicate test functions
russellwheatley Oct 20, 2025
0e0c4b7
ci: separate into 3 jobs so tests can easily be re-run
russellwheatley Oct 20, 2025
4a3eb71
ci: bump unit test timeout
russellwheatley Oct 20, 2025
193656d
Merge pull request #1276 from firebase/twitter-package
russellwheatley Oct 21, 2025
6fa2eab
refactor: google provider
russellwheatley Oct 10, 2025
8da6c91
refactor: facebook provider
russellwheatley Oct 10, 2025
c14ad31
refactor: phone auth provider
russellwheatley Oct 10, 2025
95fbb89
fix: cleaner approach to phone auth sign in
russellwheatley Oct 22, 2025
efbc028
format
russellwheatley Oct 22, 2025
2769e03
fix: phone auth is isolated within package
russellwheatley Oct 23, 2025
3a583ba
fix: remove createPhoneAuthCredential
russellwheatley Oct 23, 2025
747ba8a
fix: remove authservice from phone auth modal
russellwheatley Oct 23, 2025
2424b6c
format
russellwheatley Oct 23, 2025
e838597
Merge pull request #1277 from firebase/refactor-remaining-packages
russellwheatley Oct 23, 2025
d1f561c
feat: initial implementation of apple architecture
russellwheatley Oct 21, 2025
35d55ba
chore: setup package.swift with apple package
russellwheatley Oct 21, 2025
5ccebec
chore: import apple to test app
russellwheatley Oct 21, 2025
7f6be55
feat: support apple sign in
russellwheatley Oct 21, 2025
0cbc68e
chore: example app has apple sign in capability
russellwheatley Oct 21, 2025
d595a8b
fix: store pending credential to allow deletion of user
russellwheatley Oct 21, 2025
e92dc97
test: test the existence of apple button
russellwheatley Oct 21, 2025
ff554e4
fix: pass in apple scopes
russellwheatley Oct 21, 2025
cc56c75
Merge pull request #1278 from firebase/apple-provider
russellwheatley Oct 24, 2025
08cfd07
refactor: phone auth provider
russellwheatley Oct 10, 2025
c81680b
feat: initial OAuth setup
russellwheatley Oct 22, 2025
9493572
chore: setup test app with OAuth
russellwheatley Oct 22, 2025
6a43b96
chore: needed custom params for microsoft and yahoo
russellwheatley Oct 22, 2025
a2c8aa1
chore: remove linkedIn
russellwheatley Oct 22, 2025
44d07f8
format
russellwheatley Oct 22, 2025
10f89aa
chore: setup microsoft and yahoo sign in
russellwheatley Oct 22, 2025
058fc3e
test: test buttons are present in auth picker
russellwheatley Oct 22, 2025
08a4763
feat: use logos for microsoft, yahoo and github
russellwheatley Oct 22, 2025
5a72536
fix: remove duplicate provider
russellwheatley Oct 24, 2025
dd9e119
chore: update to use guards
russellwheatley Oct 24, 2025
a204161
ci: update timeouts
russellwheatley Oct 24, 2025
d09ff11
ci: update name of test results
russellwheatley Oct 24, 2025
f5d86be
ci: remove obsolete log for firebase logs
russellwheatley Oct 24, 2025
dbcf36d
ci: debug mode for logs
russellwheatley Oct 24, 2025
4f45eaf
test: test sometimes fails waiting for signed in screen so might be a…
russellwheatley Oct 24, 2025
4832ff7
Merge pull request #1279 from firebase/oauth-providers
russellwheatley Oct 24, 2025
d33e56f
feat: initial OAuth setup
russellwheatley Oct 22, 2025
0620f9c
refactor: use error alert modal to display errors
russellwheatley Oct 23, 2025
efee1af
chore: rename to updateError
russellwheatley Oct 23, 2025
33454f0
fix: updateError in authservice
russellwheatley Oct 23, 2025
af8a8de
refactor: ensure authservice updates error for modal
russellwheatley Oct 23, 2025
e07ef83
format
russellwheatley Oct 23, 2025
6dcf89e
chore: remove management of error from Views
russellwheatley Oct 23, 2025
82015bf
refactor: password recovery to use modal
russellwheatley Oct 23, 2025
8c3ce69
chore: remove note
russellwheatley Oct 23, 2025
fec75eb
fix: facebook error modal
russellwheatley Oct 24, 2025
a9ea643
fix: apple, google and twitter error modals
russellwheatley Oct 24, 2025
9e3219c
format
russellwheatley Oct 24, 2025
8a9019b
fix: update error for provider sign-in
russellwheatley Oct 24, 2025
2977922
test: error modal pops up for email + FB sign-in failure/cancel
russellwheatley Oct 24, 2025
a55d8dd
chore: use defer to remove duplicate code
russellwheatley Oct 27, 2025
66bc390
Merge pull request #1280 from firebase/error-refactor
russellwheatley Oct 27, 2025
91dffba
refactor: remove GoogleServiceError
russellwheatley Oct 27, 2025
56368ec
format
russellwheatley Oct 27, 2025
8696ca3
refactor: use AuthServiceError for all errors
russellwheatley Oct 27, 2025
a4b146a
fix: ensure Facebook limited or classic login occurs when selected
russellwheatley Oct 27, 2025
cda7c4c
Merge pull request #1281 from firebase/unified-auth-service-error
russellwheatley Oct 27, 2025
154e38f
Merge branch 'development' into fix-limited-login
russellwheatley Oct 27, 2025
cbed04a
refactor: remove AuthenticationToken as it is not needed
russellwheatley Oct 27, 2025
e643d78
Merge pull request #1282 from firebase/fix-limited-login
russellwheatley Oct 27, 2025
ad1f667
Merge pull request #1283 from firebase/remove-authentication-token
russellwheatley Oct 27, 2025
1028c7b
refactor: use the same reauthenticate method for providers with same …
russellwheatley Oct 27, 2025
2376da1
refactor: use the same protocol for account services
russellwheatley Oct 27, 2025
aaaf487
refactor: attempt to use one class
russellwheatley Oct 27, 2025
7c0537f
fx: make mainactor
russellwheatley Oct 27, 2025
1b14339
refactor: add phone auth to deleteUser + put in same protocol
russellwheatley Oct 27, 2025
894ff67
fix: providerId for phone
russellwheatley Oct 27, 2025
e7ada7a
fix: non sendable CI issue
russellwheatley Oct 28, 2025
d2521e2
chore: use swift v6 for example app
russellwheatley Oct 28, 2025
ed53347
fix: move mainactor
russellwheatley Oct 28, 2025
8e9b294
chore: move to swift 6
russellwheatley Oct 28, 2025
a81e9b6
feat: register library version for auth service usage
russellwheatley Oct 28, 2025
4821561
ci: update to use xcode 26
russellwheatley Oct 28, 2025
5d05bd3
ci: update iphone device
russellwheatley Oct 28, 2025
598e918
test: use main thread for test helper functions
russellwheatley Oct 29, 2025
e17ee4d
fix: do not show error modal when MFA required
russellwheatley Oct 29, 2025
4803efa
Merge pull request #1286 from firebase/account-service
russellwheatley Oct 29, 2025
f86f7e0
Merge branch 'development' into tracking-usage
russellwheatley Oct 29, 2025
4a517a2
Merge branch 'development' into stop-error-modal-on-mfa-resolution
russellwheatley Oct 29, 2025
782eca1
Merge pull request #1289 from firebase/stop-error-modal-on-mfa-resolu…
russellwheatley Oct 29, 2025
2a4f17a
chore: create release script for Swift packages
russellwheatley Oct 29, 2025
b32f11a
chore: update comment and add license header
russellwheatley Oct 29, 2025
a4c43be
Merge pull request #1287 from firebase/tracking-usage
russellwheatley Oct 29, 2025
edb8b73
fix: allow reauth on sensitive operations
russellwheatley Oct 30, 2025
a0a1435
refactor: cleaner and simpler reauth implementation
russellwheatley Oct 30, 2025
9744917
test: fix tests with MainActor annotation
russellwheatley Oct 30, 2025
046e936
refactor: remove obsolete deleteUser from every provider and AccountS…
russellwheatley Oct 30, 2025
ff8ff47
Merge pull request #1290 from firebase/reauth-mfa
russellwheatley Oct 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 140 additions & 24 deletions .github/workflows/swiftui-auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ name: SwiftUI Auth

on:
push:
branches: [ main ]
branches: [ main, development ]
paths:
- '.github/workflows/swiftui-auth.yml'
- 'samples/swiftui/**'
- 'FirebaseSwiftUI/**'
- 'Package.swift'
pull_request:
branches: [ main ]
branches: [ main, development ]
paths:
- '.github/workflows/swiftui-auth.yml'
- 'samples/swiftui/**'
Expand All @@ -22,57 +22,173 @@ permissions:
contents: read

jobs:
swiftui-auth:
runs-on: macos-15
timeout-minutes: 30
# Package Unit Tests (standalone, no emulator needed)
unit-tests:
name: Package Unit Tests
runs-on: macos-26
timeout-minutes: 15
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938

- name: Install xcpretty
run: gem install xcpretty

- name: Select Xcode version
run: sudo xcode-select -switch /Applications/Xcode_26.0.1.app/Contents/Developer

- name: Run FirebaseSwiftUI Package Unit Tests
run: |
set -o pipefail
xcodebuild test \
-scheme FirebaseUI-Package \
-destination 'platform=iOS Simulator,name=iPhone 17' \
-enableCodeCoverage YES \
-resultBundlePath FirebaseSwiftUIPackageTests.xcresult | tee FirebaseSwiftUIPackageTests.log | xcpretty --test --color --simple

- name: Upload test logs
if: failure()
uses: actions/upload-artifact@v4
with:
name: unit-tests-logs
path: FirebaseSwiftUIPackageTests.log

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: unit-tests-results
path: FirebaseSwiftUIPackageTests.xcresult

# Integration Tests (requires emulator)
integration-tests:
name: Integration Tests
runs-on: macos-26
timeout-minutes: 20
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938

- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a
name: Install Node.js 20
with:
node-version: '20'

- uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b
with:
distribution: 'temurin'
java-version: '17'

- name: Install Firebase
run: |
sudo npm i -g firebase-tools
run: sudo npm i -g firebase-tools

- name: Start Firebase Emulator
run: |
sudo chown -R 501:20 "/Users/runner/.npm" && cd ./samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample && ./start-firebase-emulator.sh
sudo chown -R 501:20 "/Users/runner/.npm"
cd ./samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample
./start-firebase-emulator.sh

- name: Install xcpretty
run: gem install xcpretty

- name: Select Xcode version
run: |
sudo xcode-select -switch /Applications/Xcode_16.3.app/Contents/Developer
- name: Run Integration Tests
run: sudo xcode-select -switch /Applications/Xcode_26.0.1.app/Contents/Developer

- name: Build for Integration Tests
run: |
cd ./samples/swiftui/FirebaseSwiftUIExample
set -o pipefail
xcodebuild test -scheme FirebaseSwiftUIExampleTests -destination 'platform=iOS Simulator,name=iPhone 16 Pro' -enableCodeCoverage YES -resultBundlePath FirebaseSwiftUIExampleTests.xcresult | tee FirebaseSwiftUIExampleTests.log | xcpretty --test --color --simple
- name: Run View UI Tests
xcodebuild build-for-testing \
-scheme FirebaseSwiftUIExampleTests \
-destination 'platform=iOS Simulator,name=iPhone 17' \
-enableCodeCoverage YES | xcpretty --color --simple

- name: Run Integration Tests
run: |
cd ./samples/swiftui/FirebaseSwiftUIExample
set -o pipefail
xcodebuild test -scheme FirebaseSwiftUIExampleUITests -destination 'platform=iOS Simulator,name=iPhone 16 Pro' -enableCodeCoverage YES -resultBundlePath FirebaseSwiftUIExampleUITests.xcresult | tee FirebaseSwiftUIExampleUITests.log | xcpretty --test --color --simple
xcodebuild test-without-building \
-scheme FirebaseSwiftUIExampleTests \
-destination 'platform=iOS Simulator,name=iPhone 17' \
-enableCodeCoverage YES \
-resultBundlePath FirebaseSwiftUIExampleTests.xcresult | tee FirebaseSwiftUIExampleTests.log | xcpretty --test --color --simple

- name: Upload test logs
if: failure()
uses: actions/upload-artifact@v4
with:
name: swiftui-auth-test-logs
path: |
samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExampleTests.log
samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExampleUITests.log
- name: Upload FirebaseSwiftUIExampleUITests.xcresult bundle
name: integration-tests-logs
path: samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExampleTests.log

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: FirebaseSwiftUIExampleUITests.xcresult
path: samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExampleUITests.xcresult
- name: Upload FirebaseSwiftUIExampleTests.xcresult bundle
name: integration-tests-results
path: samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExampleTests.xcresult

# UI Tests (requires emulator)
ui-tests:
name: UI Tests
runs-on: macos-26
timeout-minutes: 40
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938

- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a
name: Install Node.js 20
with:
node-version: '20'

- uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b
with:
distribution: 'temurin'
java-version: '17'

- name: Install Firebase
run: sudo npm i -g firebase-tools

- name: Start Firebase Emulator
run: |
sudo chown -R 501:20 "/Users/runner/.npm"
cd ./samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample
./start-firebase-emulator.sh

- name: Install xcpretty
run: gem install xcpretty

- name: Select Xcode version
run: sudo xcode-select -switch /Applications/Xcode_26.0.1.app/Contents/Developer

- name: Build for UI Tests
run: |
cd ./samples/swiftui/FirebaseSwiftUIExample
set -o pipefail
xcodebuild build-for-testing \
-scheme FirebaseSwiftUIExampleUITests \
-destination 'platform=iOS Simulator,name=iPhone 17' \
-enableCodeCoverage YES | xcpretty --color --simple

- name: Run UI Tests
run: |
cd ./samples/swiftui/FirebaseSwiftUIExample
set -o pipefail
xcodebuild test-without-building \
-scheme FirebaseSwiftUIExampleUITests \
-destination 'platform=iOS Simulator,name=iPhone 17' \
-parallel-testing-enabled YES \
-maximum-concurrent-test-simulator-destinations 2 \
-enableCodeCoverage YES \
-resultBundlePath FirebaseSwiftUIExampleUITests.xcresult | tee FirebaseSwiftUIExampleUITests.log | xcpretty --test --color --simple

- name: Upload Firebase Emulator logs
if: failure()
uses: actions/upload-artifact@v4
with:
name: FirebaseSwiftUIExampleTests.xcresult
path: samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExampleTests.xcresult
name: firebase-emulator-logs
path: samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample/firebase-debug.log

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: FirebaseSwiftUIExampleUITests.xcresult
path: samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExampleUITests.xcresult
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import AuthenticationServices
import CryptoKit
import FirebaseAuth
import FirebaseAuthSwiftUI
import FirebaseCore
import SwiftUI

// MARK: - Data Extensions

extension Data {
var utf8String: String? {
return String(data: self, encoding: .utf8)
}
}

extension ASAuthorizationAppleIDCredential {
var authorizationCodeString: String? {
return authorizationCode?.utf8String
}

var idTokenString: String? {
return identityToken?.utf8String
}
}

// MARK: - Authenticate With Apple Dialog

private func authenticateWithApple(scopes: [ASAuthorization.Scope]) async throws -> (
ASAuthorizationAppleIDCredential,
String
) {
return try await AuthenticateWithAppleDialog(scopes: scopes).authenticate()
}

private class AuthenticateWithAppleDialog: NSObject {
private var continuation: CheckedContinuation<(ASAuthorizationAppleIDCredential, String), Error>?
private var currentNonce: String?
private let scopes: [ASAuthorization.Scope]

init(scopes: [ASAuthorization.Scope]) {
self.scopes = scopes
super.init()
}

func authenticate() async throws -> (ASAuthorizationAppleIDCredential, String) {
return try await withCheckedThrowingContinuation { continuation in
self.continuation = continuation

let appleIDProvider = ASAuthorizationAppleIDProvider()
let request = appleIDProvider.createRequest()
request.requestedScopes = scopes

do {
let nonce = try CryptoUtils.randomNonceString()
currentNonce = nonce
request.nonce = CryptoUtils.sha256(nonce)
} catch {
continuation.resume(throwing: AuthServiceError.signInFailed(underlying: error))
return
}

let authorizationController = ASAuthorizationController(authorizationRequests: [request])
authorizationController.delegate = self
authorizationController.performRequests()
}
}
}

extension AuthenticateWithAppleDialog: ASAuthorizationControllerDelegate {
func authorizationController(controller _: ASAuthorizationController,
didCompleteWithAuthorization authorization: ASAuthorization) {
if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {
if let nonce = currentNonce {
continuation?.resume(returning: (appleIDCredential, nonce))
} else {
continuation?.resume(
throwing: AuthServiceError.signInFailed(
underlying: NSError(
domain: "AppleSignIn",
code: -1,
userInfo: [NSLocalizedDescriptionKey: "Missing nonce"]
)
)
)
}
} else {
continuation?.resume(
throwing: AuthServiceError.invalidCredentials("Missing Apple ID credential")
)
}
continuation = nil
}

func authorizationController(controller _: ASAuthorizationController,
didCompleteWithError error: Error) {
continuation?.resume(throwing: AuthServiceError.signInFailed(underlying: error))
continuation = nil
}
}

// MARK: - Apple Provider Swift

public class AppleProviderSwift: AuthProviderSwift {
public let scopes: [ASAuthorization.Scope]
let providerId = "apple.com"

public init(scopes: [ASAuthorization.Scope] = [.fullName, .email]) {
self.scopes = scopes
}

@MainActor public func createAuthCredential() async throws -> AuthCredential {
let (appleIDCredential, nonce) = try await authenticateWithApple(scopes: scopes)

guard let idTokenString = appleIDCredential.idTokenString else {
throw AuthServiceError.invalidCredentials("Unable to fetch identity token from Apple")
}

let credential = OAuthProvider.appleCredential(
withIDToken: idTokenString,
rawNonce: nonce,
fullName: appleIDCredential.fullName
)

return credential
}
}

public class AppleProviderAuthUI: AuthProviderUI {
public var provider: AuthProviderSwift

public init(provider: AuthProviderSwift) {
self.provider = provider
}

public let id: String = "apple.com"

@MainActor public func authButton() -> AnyView {
AnyView(SignInWithAppleButton(provider: provider))
}
}
Loading
Loading