Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit d098eea

Browse files
authored
Merge pull request #138 from wordpress-mobile/issue/12535-siwa_observe_revoked_notification
[SIWA] Observe Apple Credential Revoked notification
2 parents f4656f5 + 4b6daab commit d098eea

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

WordPressAuthenticator.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "WordPressAuthenticator"
3-
s.version = "1.10.0-beta.1"
3+
s.version = "1.10.0-beta.2"
44
s.summary = "WordPressAuthenticator implements an easy and elegant way to authenticate your WordPress Apps."
55

66
s.description = <<-DESC

WordPressAuthenticator/Authenticator/WordPressAuthenticator.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import WordPressUI
1414
///
1515
private static var privateInstance: WordPressAuthenticator?
1616

17+
/// Observer for AppleID Credential State
18+
///
19+
private var appleIDCredentialObserver: NSObjectProtocol?
20+
1721
/// Shared Instance.
1822
///
1923
@objc public static var shared: WordPressAuthenticator {
@@ -465,10 +469,25 @@ import WordPressUI
465469

466470
@available(iOS 13.0, *)
467471
public extension WordPressAuthenticator {
472+
468473
func checkAppleIDCredentialState(for userID: String, completion: @escaping (Bool, Error?) -> Void) {
469474
AppleAuthenticator.sharedInstance.checkAppleIDCredentialState(for: userID) { (state, error) in
470475
// If credentialState == .notFound, error will have a value.
471-
completion(state == .authorized, error)
476+
completion(state != .revoked, error)
477+
}
478+
}
479+
480+
func startObservingAppleIDCredentialRevoked(completion: @escaping () -> Void) {
481+
appleIDCredentialObserver = NotificationCenter.default.addObserver(forName: AppleAuthenticator.credentialRevokedNotification, object: nil, queue: nil) { (notification) in
482+
completion()
472483
}
473484
}
485+
486+
func stopObservingAppleIDCredentialRevoked() {
487+
if let observer = appleIDCredentialObserver {
488+
NotificationCenter.default.removeObserver(observer)
489+
}
490+
appleIDCredentialObserver = nil
491+
}
492+
474493
}

WordPressAuthenticator/Signin/AppleAuthenticator.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class AppleAuthenticator: NSObject {
1717
private var showFromViewController: UIViewController?
1818
private let loginFields = LoginFields()
1919
weak var delegate: AppleAuthenticatorDelegate?
20+
21+
@available(iOS 13.0, *)
22+
static let credentialRevokedNotification = ASAuthorizationAppleIDProvider.credentialRevokedNotification
2023

2124
private var authenticationDelegate: WordPressAuthenticatorDelegate {
2225
guard let delegate = WordPressAuthenticator.shared.delegate else {

0 commit comments

Comments
 (0)