aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase/Auth/Source/RPCs/FIRAuthBackend.h
blob: 519a6e7f7fd0e34778d11b4e79f32c990aa71afc (plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
/*
 * Copyright 2017 Google
 *
 * 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 <Foundation/Foundation.h>

@class FIRCreateAuthURIRequest;
@class FIRCreateAuthURIResponse;
@class FIRGetAccountInfoRequest;
@class FIRGetAccountInfoResponse;
@class FIRGetOOBConfirmationCodeRequest;
@class FIRGetOOBConfirmationCodeResponse;
@class FIRResetPasswordRequest;
@class FIRResetPasswordResponse;
@class FIRSecureTokenRequest;
@class FIRSecureTokenResponse;
@class FIRSetAccountInfoRequest;
@class FIRSetAccountInfoResponse;
@class FIRVerifyAssertionRequest;
@class FIRVerifyAssertionResponse;
@class FIRVerifyClientRequest;
@class FIRVerifyClientResponse;
@class FIRVerifyCustomTokenRequest;
@class FIRVerifyCustomTokenResponse;
@class FIRVerifyPasswordRequest;
@class FIRVerifyPasswordResponse;
@class FIRVerifyPhoneNumberRequest;
@class FIRVerifyPhoneNumberResponse;
@class FIRSendVerificationCodeRequest;
@class FIRSendVerificationCodeResponse;
@class FIRSignUpNewUserRequest;
@class FIRSignUpNewUserResponse;
@class FIRDeleteAccountRequest;
@class FIRDeleteAccountResponse;
@protocol FIRAuthBackendImplementation;
@protocol FIRAuthBackendRPCIssuer;

NS_ASSUME_NONNULL_BEGIN

/** @typedef FIRAuthBackendRPCIssuerCompletionHandler
    @brief The type of block used to return the result of a call to an endpoint.
    @param data The HTTP response body.
    @param error The error which occurred, if any.
    @remarks One of response or error will be non-nil.
 */
typedef void (^FIRAuthBackendRPCIssuerCompletionHandler)(NSData *_Nullable data,
                                                         NSError *_Nullable error);

/** @typedef FIRCreateAuthURIResponseCallback
    @brief The type of block used to return the result of a call to the createAuthURI
        endpoint.
    @param response The received response, if any.
    @param error The error which occurred, if any.
    @remarks One of response or error will be non-nil.
 */
typedef void (^FIRCreateAuthURIResponseCallback)
    (FIRCreateAuthURIResponse *_Nullable response, NSError *_Nullable error);

/** @typedef FIRGetAccountInfoResponseCallback
    @brief The type of block used to return the result of a call to the getAccountInfo
        endpoint.
    @param response The received response, if any.
    @param error The error which occurred, if any.
    @remarks One of response or error will be non-nil.
 */
typedef void (^FIRGetAccountInfoResponseCallback)
    (FIRGetAccountInfoResponse *_Nullable response, NSError *_Nullable error);

/** @typedef FIRSetAccountInfoResponseCallback
    @brief The type of block used to return the result of a call to the setAccountInfo
        endpoint.
    @param response The received response, if any.
    @param error The error which occurred, if any.
    @remarks One of response or error will be non-nil.
 */
typedef void (^FIRSetAccountInfoResponseCallback)
    (FIRSetAccountInfoResponse *_Nullable response, NSError *_Nullable error);

/** @typedef FIRSecureTokenResponseCallback
    @brief The type of block used to return the result of a call to the token endpoint.
    @param response The received response, if any.
    @param error The error which occurred, if any.
    @remarks One of response or error will be non-nil.
 */
typedef void (^FIRSecureTokenResponseCallback)
    (FIRSecureTokenResponse *_Nullable response, NSError *_Nullable error);

/** @typedef FIRVerifyAssertionResponseCallback
    @brief The type of block used to return the result of a call to the verifyAssertion
        endpoint.
    @param response The received response, if any.
    @param error The error which occurred, if any.
    @remarks One of response or error will be non-nil.
 */
typedef void (^FIRVerifyAssertionResponseCallback)
    (FIRVerifyAssertionResponse *_Nullable response, NSError *_Nullable error);

/** @typedef FIRVerifyPasswordResponseCallback
    @brief The type of block used to return the result of a call to the verifyPassword
        endpoint.
    @param response The received response, if any.
    @param error The error which occurred, if any.
    @remarks One of response or error will be non-nil.
 */
typedef void (^FIRVerifyPasswordResponseCallback)
    (FIRVerifyPasswordResponse *_Nullable response, NSError *_Nullable error);

/** @typedef FIRVerifyCustomTokenResponseCallback
    @brief The type of block used to return the result of a call to the verifyCustomToken
        endpoint.
    @param response The received response, if any.
    @param error The error which occurred, if any.
    @remarks One of response or error will be non-nil.
 */
typedef void (^FIRVerifyCustomTokenResponseCallback)
    (FIRVerifyCustomTokenResponse *_Nullable response, NSError *_Nullable error);

/** @typedef FIRDeleteCallBack
    @brief The type of block called when a request delete account has finished.
    @param error The error which occurred, or nil if the request was successful.
 */
typedef void (^FIRDeleteCallBack)(NSError *_Nullable error);

/** @typedef FIRGetOOBConfirmationCodeResponseCallback
    @brief The type of block used to return the result of a call to the getOOBConfirmationCode
        endpoint.
    @param response The received response, if any.
    @param error The error which occurred, if any.
    @remarks One of response or error will be non-nil.
 */
typedef void (^FIRGetOOBConfirmationCodeResponseCallback)
    (FIRGetOOBConfirmationCodeResponse *_Nullable response, NSError *_Nullable error);

/** @typedef FIRSignupNewUserCallback
    @brief The type of block used to return the result of a call to the signupNewUser endpoint.
    @param response The received response, if any.
    @param error The error which occurred, if any.
    @remarks One of response or error will be non-nil.
 */
typedef void (^FIRSignupNewUserCallback)
    (FIRSignUpNewUserResponse *_Nullable response, NSError *_Nullable error);

/** @typedef FIRResetPasswordCallback
    @brief The type of block used to return the result of a call to the resetPassword endpoint.
    @param response The received response, if any.
    @param error The error which occurred, if any.
    @remarks One of response or error will be non-nil.
 */
typedef void (^FIRResetPasswordCallback)
    (FIRResetPasswordResponse *_Nullable response, NSError *_Nullable error);

/** @typedef FIRSendVerificationCodeResponseCallback
    @brief The type of block used to return the result of a call to the sendVerificationCode
        endpoint.
    @param response The received response, if any.
    @param error The error which occurred, if any.
    @remarks One of response or error will be non-nil.
 */
typedef void (^FIRSendVerificationCodeResponseCallback)
    (FIRSendVerificationCodeResponse *_Nullable response, NSError *_Nullable error);

/** @typedef FIRVerifyPhoneNumberResponseCallback
    @brief The type of block used to return the result of a call to the verifyPhoneNumber endpoint.
    @param response The received response, if any.
    @param error The error which occurred, if any.
    @remarks One of response or error will be non-nil.
 */
typedef void (^FIRVerifyPhoneNumberResponseCallback)
    (FIRVerifyPhoneNumberResponse *_Nullable response, NSError *_Nullable error);

/** @typedef FIRVerifyClientResponseCallback
    @brief The type of block used to return the result of a call to the verifyClient endpoint.
    @param response The received response, if any.
    @param error The error which occurred, if any.
    @remarks One of response or error will be non-nil.
 */
typedef void (^FIRVerifyClientResponseCallback)
    (FIRVerifyClientResponse *_Nullable response, NSError *_Nullable error);

/** @class FIRAuthBackend
    @brief Simple static class with methods representing the backend RPCs.
    @remarks All callback blocks passed as method parameters are invoked asynchronously on the
        global work queue in the future. See
        https://github.com/firebase/firebase-ios-sdk/tree/master/Firebase/Auth/Docs/threading.ml
 */
@interface FIRAuthBackend : NSObject

/** @fn setBackendImplementation:
    @brief Changes the default backend implementation to something else.
    @param backendImplementation The backend implementation to use.
    @remarks This is not, generally, safe to call in a scenario where other backend requests may
        be occuring. This is specifically to help mock the backend for testing purposes.
 */
+ (void)setBackendImplementation:(id<FIRAuthBackendImplementation>)backendImplementation;

/** @fn setDefaultBackendImplementationWithRPCIssuer:
    @brief Uses the default backend implementation, but with a custom RPC issuer.
    @param RPCIssuer The RPC issuer to use. If @c nil, will use the default implementation.
    @remarks This is not, generally, safe to call in a scenario where other backend requests may
        be occuring. This is specifically to help test the backend interfaces (requests, responses,
        and shared FIRAuthBackend logic.)
 */
+ (void)setDefaultBackendImplementationWithRPCIssuer:
    (nullable id<FIRAuthBackendRPCIssuer>)RPCIssuer;

/** @fn createAuthURI:callback:
    @brief Calls the createAuthURI endpoint, which is responsible for creating the URI used by the
        IdP to authenticate the user.
    @param request The request parameters.
    @param callback The callback.
 */
+ (void)createAuthURI:(FIRCreateAuthURIRequest *)request
             callback:(FIRCreateAuthURIResponseCallback)callback;

/** @fn getAccountInfo:callback:
    @brief Calls the getAccountInfo endpoint, which returns account info for a given account.
    @param request The request parameters.
    @param callback The callback.
 */
+ (void)getAccountInfo:(FIRGetAccountInfoRequest *)request
              callback:(FIRGetAccountInfoResponseCallback)callback;

/** @fn setAccountInfo:callback:
    @brief Calls the setAccountInfo endpoint, which is responsible for setting account info for a
        user, for example, to sign up a new user with email and password.
    @param request The request parameters.
    @param callback The callback.
 */
+ (void)setAccountInfo:(FIRSetAccountInfoRequest *)request
              callback:(FIRSetAccountInfoResponseCallback)callback;

/** @fn verifyAssertion:callback:
    @brief Calls the verifyAssertion endpoint, which is responsible for authenticating a
        user who has IDP-related credentials (an ID Token, an Access Token, etc.)
    @param request The request parameters.
    @param callback The callback.
 */
+ (void)verifyAssertion:(FIRVerifyAssertionRequest *)request
               callback:(FIRVerifyAssertionResponseCallback)callback;

/** @fn verifyCustomToken:callback:
    @brief Calls the verifyCustomToken endpoint, which is responsible for authenticating a
        user who has BYOAuth credentials (a self-signed token using their BYOAuth private key.)
    @param request The request parameters.
    @param callback The callback.
 */
+ (void)verifyCustomToken:(FIRVerifyCustomTokenRequest *)request
                 callback:(FIRVerifyCustomTokenResponseCallback)callback;

/** @fn verifyPassword:callback:
    @brief Calls the verifyPassword endpoint, which is responsible for authenticating a
        user who has email and password credentials.
    @param request The request parameters.
    @param callback The callback.
 */
+ (void)verifyPassword:(FIRVerifyPasswordRequest *)request
              callback:(FIRVerifyPasswordResponseCallback)callback;

/** @fn secureToken:callback:
    @brief Calls the token endpoint, which is responsible for performing STS token exchanges and
        token refreshes.
    @param request The request parameters.
    @param callback The callback.
 */
+ (void)secureToken:(FIRSecureTokenRequest *)request
           callback:(FIRSecureTokenResponseCallback)callback;

/** @fn getOOBConfirmationCode:callback:
    @brief Calls the getOOBConfirmationCode endpoint, which is responsible for sending email change
        request emails, and password reset emails.
    @param request The request parameters.
    @param callback The callback.
 */
+ (void)getOOBConfirmationCode:(FIRGetOOBConfirmationCodeRequest *)request
                      callback:(FIRGetOOBConfirmationCodeResponseCallback)callback;

/** @fn signUpNewUser:
    @brief Calls the signUpNewUser endpoint, which is responsible anonymously signing up a user
        or signing in a user anonymously.
    @param request The request parameters.
    @param callback The callback.
 */
+ (void)signUpNewUser:(FIRSignUpNewUserRequest *)request
             callback:(FIRSignupNewUserCallback)callback;

/** @fn resetPassword:callback
    @brief Calls the resetPassword endpoint, which is responsible for resetting a user's password
      given an OOB code and new password.
    @param request The request parameters.
    @param callback The callback.
 */
+ (void)resetPassword:(FIRResetPasswordRequest *)request
             callback:(FIRResetPasswordCallback)callback;

/** @fn deleteAccount:
    @brief Calls the DeleteAccount endpoint, which is responsible for deleting a user.
    @param request The request parameters.
    @param callback The callback.
 */
+ (void)deleteAccount:(FIRDeleteAccountRequest *)request
             callback:(FIRDeleteCallBack)callback;

/** @fn sendVerificationCode:callback:
    @brief Calls the sendVerificationCode endpoint, which is responsible for sending the
        verification code to a phone number specified in the request parameters.
    @param request The request parameters.
    @param callback The callback.
 */
+ (void)sendVerificationCode:(FIRSendVerificationCodeRequest *)request
                    callback:(FIRSendVerificationCodeResponseCallback)callback;

/** @fn verifyPhoneNumber:callback:
    @brief Calls the verifyPhoneNumber endpoint, which is responsible for sending the verification
        code to a phone number specified in the request parameters.
    @param request The request parameters.
    @param callback The callback.
 */
+ (void)verifyPhoneNumber:(FIRVerifyPhoneNumberRequest *)request
                 callback:(FIRVerifyPhoneNumberResponseCallback)callback;

/** @fn verifyClient:callback:
    @brief Calls the verifyClient endpoint, which is responsible for sending the silent push
        notification used for app validation to the device provided in the request parameters.
    @param request The request parameters.
    @param callback The callback.
 */
+ (void)verifyClient:(FIRVerifyClientRequest *)request
            callback:(FIRVerifyClientResponseCallback)callback;

@end

/** @protocol FIRAuthBackendRPCIssuer
    @brief Used to make FIRAuthBackend
 */
@protocol FIRAuthBackendRPCIssuer <NSObject>

/** @fn asyncPostToURL:body:contentType:completionHandler:
    @brief Asynchronously sends a POST request.
    @param URL URL of the request.
    @param body Request body.
    @param contentType Content type of the body.
    @param handler provided that handles POST response. Invoked asynchronously on the auth global
        work queue in the future.
 */
- (void)asyncPostToURL:(NSURL *)URL
                  body:(NSData *)body
           contentType:(NSString *)contentType
     completionHandler:(FIRAuthBackendRPCIssuerCompletionHandler)handler;

@end

/** @protocol FIRAuthBackendImplementation
    @brief Used to make FIRAuthBackend provide a layer of indirection to an actual RPC-based backend
        or a mock backend.
 */
@protocol FIRAuthBackendImplementation <NSObject>

/** @fn createAuthURI:callback:
    @brief Calls the createAuthURI endpoint, which is responsible for creating the URI used by the
        IdP to authenticate the user.
    @param request The request parameters.
    @param callback The callback.
 */
- (void)createAuthURI:(FIRCreateAuthURIRequest *)request
             callback:(FIRCreateAuthURIResponseCallback)callback;

/** @fn getAccountInfo:callback:
    @brief Calls the getAccountInfo endpoint, which returns account info for a given account.
    @param request The request parameters.
    @param callback The callback.
 */
- (void)getAccountInfo:(FIRGetAccountInfoRequest *)request
              callback:(FIRGetAccountInfoResponseCallback)callback;

/** @fn setAccountInfo:callback:
    @brief Calls the setAccountInfo endpoint, which is responsible for setting account info for a
        user, for example, to sign up a new user with email and password.
    @param request The request parameters.
    @param callback The callback.
 */
- (void)setAccountInfo:(FIRSetAccountInfoRequest *)request
              callback:(FIRSetAccountInfoResponseCallback)callback;

/** @fn verifyAssertion:callback:
    @brief Calls the verifyAssertion endpoint, which is responsible for authenticating a
        user who has IDP-related credentials (an ID Token, an Access Token, etc.)
    @param request The request parameters.
    @param callback The callback.
 */
- (void)verifyAssertion:(FIRVerifyAssertionRequest *)request
               callback:(FIRVerifyAssertionResponseCallback)callback;

/** @fn verifyCustomToken:callback:
    @brief Calls the verifyCustomToken endpoint, which is responsible for authenticating a
        user who has BYOAuth credentials (a self-signed token using their BYOAuth private key.)
    @param request The request parameters.
    @param callback The callback.
 */
- (void)verifyCustomToken:(FIRVerifyCustomTokenRequest *)request
                 callback:(FIRVerifyCustomTokenResponseCallback)callback;

/** @fn verifyPassword:callback:
    @brief Calls the verifyPassword endpoint, which is responsible for authenticating a
        user who has email and password credentials.
    @param request The request parameters.
    @param callback The callback.
 */
- (void)verifyPassword:(FIRVerifyPasswordRequest *)request
              callback:(FIRVerifyPasswordResponseCallback)callback;

/** @fn secureToken:callback:
    @brief Calls the token endpoint, which is responsible for performing STS token exchanges and
        token refreshes.
    @param request The request parameters.
    @param callback The callback.
 */
- (void)secureToken:(FIRSecureTokenRequest *)request
           callback:(FIRSecureTokenResponseCallback)callback;

/** @fn getOOBConfirmationCode:callback:
    @brief Calls the getOOBConfirmationCode endpoint, which is responsible for sending email change
        request emails, and password reset emails.
    @param request The request parameters.
    @param callback The callback.
 */
- (void)getOOBConfirmationCode:(FIRGetOOBConfirmationCodeRequest *)request
                      callback:(FIRGetOOBConfirmationCodeResponseCallback)callback;

/** @fn signUpNewUser:
    @brief Calls the signUpNewUser endpoint, which is responsible anonymously signing up a user
        or signing in a user anonymously.
    @param request The request parameters.
    @param callback The callback.
 */
- (void)signUpNewUser:(FIRSignUpNewUserRequest *)request
             callback:(FIRSignupNewUserCallback)callback;

/** @fn deleteAccount:
    @brief Calls the DeleteAccount endpoint, which is responsible for deleting a user.
    @param request The request parameters.
    @param callback The callback.
 */
- (void)deleteAccount:(FIRDeleteAccountRequest *)request
             callback:(FIRDeleteCallBack)callback;

/** @fn sendVerificationCode:callback:
    @brief Calls the sendVerificationCode endpoint, which is responsible for sending the
        verification code to a phone number specified in the request parameters.
    @param request The request parameters.
    @param callback The callback.
 */
- (void)sendVerificationCode:(FIRSendVerificationCodeRequest *)request
                    callback:(FIRSendVerificationCodeResponseCallback)callback;

/** @fn verifyPhoneNumber:callback:
    @brief Calls the verifyPhoneNumber endpoint, which is responsible for sending the verification
        code to a phone number specified in the request parameters.
    @param request The request parameters.
    @param callback The callback.
 */
- (void)verifyPhoneNumber:(FIRVerifyPhoneNumberRequest *)request
                 callback:(FIRVerifyPhoneNumberResponseCallback)callback;

/** @fn verifyClient:callback:
    @brief Calls the verifyClient endpoint, which is responsible for sending the silent push
        notification used for app validation to the device provided in the request parameters.
    @param request The request parameters.
    @param callback The callback.
 */
- (void)verifyClient:(FIRVerifyClientRequest *)request
            callback:(FIRVerifyClientResponseCallback)callback;

/** @fn resetPassword:callback
    @brief Calls the resetPassword endpoint, which is responsible for resetting a user's password
      given an OOB code and new password.
    @param request The request parameters.
    @param callback The callback.
 */
- (void)resetPassword:(FIRResetPasswordRequest *)request
             callback:(FIRResetPasswordCallback)callback;

@end

NS_ASSUME_NONNULL_END