-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSFWebServiceAuthentication.swift
35 lines (30 loc) · 1.25 KB
/
SFWebServiceAuthentication.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
// SFWebServiceAuthentication.swift
// IFTTTConnectSDK
//
// Copyright © 2021 IFTTT. All rights reserved.
//
import SafariServices
/// Wraps an `SFAuthenticationSession`. Used to authenticate web services up to (not including) iOS 12.
@available(iOS 11.0, *)
@available(iOS, deprecated: 12, obsoleted: 13, message: "API is deprecated in iOS 12 and obsoleted in iOS 13")
final class SFWebService: WebServiceAuthentication {
/// The backing `SFAuthenticationSession` object.
private var session: SFAuthenticationSession?
@discardableResult
override func start(with parameters: Parameters, completionHandler: @escaping (Result<URL, AuthenticationError>) -> Void) -> Bool {
let sfAuthenticationSession = SFAuthenticationSession(url: parameters.url,
callbackURLScheme: parameters.callbackURLScheme) { url, error in
guard error == nil, let url = url else {
completionHandler(.failure(.userCanceled))
return
}
completionHandler(.success(url))
}
self.session = sfAuthenticationSession
return sfAuthenticationSession.start()
}
override func cancel() {
session?.cancel()
}
}