|
7 | 7 | //
|
8 | 8 |
|
9 | 9 | import Foundation
|
| 10 | +#if canImport(Combine) |
| 11 | +import Combine |
| 12 | +#endif |
10 | 13 |
|
11 | 14 | // swiftlint:disable line_length
|
12 | 15 |
|
@@ -90,6 +93,41 @@ public extension ParseApple {
|
90 | 93 | callbackQueue: callbackQueue,
|
91 | 94 | completion: completion)
|
92 | 95 | }
|
| 96 | + |
| 97 | + #if canImport(Combine) |
| 98 | + |
| 99 | + /** |
| 100 | + Login a `ParseUser` *asynchronously* using Apple authentication. Publishes when complete. |
| 101 | + - parameter user: The `user` from `ASAuthorizationAppleIDCredential`. |
| 102 | + - parameter identityToken: The `identityToken` from `ASAuthorizationAppleIDCredential`. |
| 103 | + - parameter options: A set of header options sent to the server. Defaults to an empty set. |
| 104 | + - returns: A publisher that eventually produces a single value and then finishes or fails. |
| 105 | + */ |
| 106 | + @available(macOS 10.15, iOS 13.0, macCatalyst 13.0, watchOS 6.0, tvOS 13.0, *) |
| 107 | + func loginPublisher(user: String, |
| 108 | + identityToken: String, |
| 109 | + options: API.Options = []) -> Future<AuthenticatedUser, ParseError> { |
| 110 | + loginPublisher(authData: AuthenticationKeys.id.makeDictionary(user: user, identityToken: identityToken), |
| 111 | + options: options) |
| 112 | + } |
| 113 | + |
| 114 | + @available(macOS 10.15, iOS 13.0, macCatalyst 13.0, watchOS 6.0, tvOS 13.0, *) |
| 115 | + func loginPublisher(authData: [String: String]?, |
| 116 | + options: API.Options = []) -> Future<AuthenticatedUser, ParseError> { |
| 117 | + guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData), |
| 118 | + let authData = authData else { |
| 119 | + let error = ParseError(code: .unknownError, |
| 120 | + message: "Should have authData in consisting of keys \"id\" and \"token\".") |
| 121 | + return Future { promise in |
| 122 | + promise(.failure(error)) |
| 123 | + } |
| 124 | + } |
| 125 | + return AuthenticatedUser.loginPublisher(Self.__type, |
| 126 | + authData: authData, |
| 127 | + options: options) |
| 128 | + } |
| 129 | + |
| 130 | + #endif |
93 | 131 | }
|
94 | 132 |
|
95 | 133 | // MARK: Link
|
@@ -133,6 +171,41 @@ public extension ParseApple {
|
133 | 171 | callbackQueue: callbackQueue,
|
134 | 172 | completion: completion)
|
135 | 173 | }
|
| 174 | + |
| 175 | + #if canImport(Combine) |
| 176 | + |
| 177 | + /** |
| 178 | + Link the *current* `ParseUser` *asynchronously* using Apple authentication. Publishes when complete. |
| 179 | + - parameter user: The `user` from `ASAuthorizationAppleIDCredential`. |
| 180 | + - parameter identityToken: The `identityToken` from `ASAuthorizationAppleIDCredential`. |
| 181 | + - parameter options: A set of header options sent to the server. Defaults to an empty set. |
| 182 | + - returns: A publisher that eventually produces a single value and then finishes or fails. |
| 183 | + */ |
| 184 | + @available(macOS 10.15, iOS 13.0, macCatalyst 13.0, watchOS 6.0, tvOS 13.0, *) |
| 185 | + func linkPublisher(user: String, |
| 186 | + identityToken: String, |
| 187 | + options: API.Options = []) -> Future<AuthenticatedUser, ParseError> { |
| 188 | + linkPublisher(authData: AuthenticationKeys.id.makeDictionary(user: user, identityToken: identityToken), |
| 189 | + options: options) |
| 190 | + } |
| 191 | + |
| 192 | + @available(macOS 10.15, iOS 13.0, macCatalyst 13.0, watchOS 6.0, tvOS 13.0, *) |
| 193 | + func linkPublisher(authData: [String: String]?, |
| 194 | + options: API.Options = []) -> Future<AuthenticatedUser, ParseError> { |
| 195 | + guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData), |
| 196 | + let authData = authData else { |
| 197 | + let error = ParseError(code: .unknownError, |
| 198 | + message: "Should have authData in consisting of keys \"id\" and \"token\".") |
| 199 | + return Future { promise in |
| 200 | + promise(.failure(error)) |
| 201 | + } |
| 202 | + } |
| 203 | + return AuthenticatedUser.linkPublisher(Self.__type, |
| 204 | + authData: authData, |
| 205 | + options: options) |
| 206 | + } |
| 207 | + |
| 208 | + #endif |
136 | 209 | }
|
137 | 210 |
|
138 | 211 | // MARK: 3rd Party Authentication - ParseApple
|
|
0 commit comments