-
-
Notifications
You must be signed in to change notification settings - Fork 452
Expand file tree
/
Copy pathAuth.php
More file actions
472 lines (426 loc) · 16.7 KB
/
Copy pathAuth.php
File metadata and controls
472 lines (426 loc) · 16.7 KB
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
<?php
declare(strict_types=1);
namespace Kreait\Firebase\Contract;
use DateInterval;
use InvalidArgumentException;
use Kreait\Firebase\Auth\ActionCodeSettings;
use Kreait\Firebase\Auth\CreateActionLink\FailedToCreateActionLink;
use Kreait\Firebase\Auth\CreateSessionCookie\FailedToCreateSessionCookie;
use Kreait\Firebase\Auth\DeleteUsersResult;
use Kreait\Firebase\Auth\SendActionLink\FailedToSendActionLink;
use Kreait\Firebase\Auth\SignIn\FailedToSignIn;
use Kreait\Firebase\Auth\SignInResult;
use Kreait\Firebase\Auth\UserQuery;
use Kreait\Firebase\Auth\UserRecord;
use Kreait\Firebase\Exception;
use Kreait\Firebase\Exception\Auth\ExpiredOobCode;
use Kreait\Firebase\Exception\Auth\FailedToVerifySessionCookie;
use Kreait\Firebase\Exception\Auth\FailedToVerifyToken;
use Kreait\Firebase\Exception\Auth\InvalidOobCode;
use Kreait\Firebase\Exception\Auth\OperationNotAllowed;
use Kreait\Firebase\Exception\Auth\RevokedIdToken;
use Kreait\Firebase\Exception\Auth\RevokedSessionCookie;
use Kreait\Firebase\Exception\Auth\UserDisabled;
use Kreait\Firebase\Exception\Auth\UserNotFound;
use Kreait\Firebase\Request\CreateUser;
use Kreait\Firebase\Request\UpdateUser;
use Lcobucci\JWT\Token;
use Lcobucci\JWT\UnencryptedToken;
use Traversable;
/**
* @phpstan-import-type UserQueryShape from UserQuery
*/
interface Auth
{
/**
* @param non-empty-string $uid
*
* @throws UserNotFound
* @throws Exception\AuthException
* @throws Exception\FirebaseException
*/
public function getUser(string $uid): UserRecord;
/**
* @param non-empty-list<non-empty-string> $uids
*
* @throws Exception\AuthException
* @throws Exception\FirebaseException
*
* @return array<non-empty-string, UserRecord|null>
*/
public function getUsers(array $uids): array;
/**
* @param UserQuery|UserQueryShape $query
*
* @throws Exception\FirebaseException
* @throws Exception\AuthException
*
* @return array<non-empty-string, UserRecord>
*/
public function queryUsers(UserQuery|array $query): array;
/**
* @param positive-int $maxResults
* @param positive-int $batchSize
*
* @throws Exception\FirebaseException
* @throws Exception\AuthException
*
* @return Traversable<UserRecord>
*/
public function listUsers(int $maxResults = 1000, int $batchSize = 1000): Traversable;
/**
* Creates a new user with the provided properties.
*
* @param array<non-empty-string, mixed>|CreateUser $properties
*
* @throws Exception\AuthException
* @throws Exception\FirebaseException
*/
public function createUser(array|CreateUser $properties): UserRecord;
/**
* Updates the given user with the given properties.
*
* @param non-empty-string $uid
* @param non-empty-array<non-empty-string, mixed>|UpdateUser $properties
*
* @throws Exception\AuthException
* @throws Exception\FirebaseException
*/
public function updateUser(string $uid, array|UpdateUser $properties): UserRecord;
/**
* @param non-empty-string $email
* @param non-empty-string $password
*
* @throws Exception\AuthException
* @throws Exception\FirebaseException
*/
public function createUserWithEmailAndPassword(string $email, string $password): UserRecord;
/**
* @param non-empty-string $email
*
* @throws UserNotFound
* @throws Exception\AuthException
* @throws Exception\FirebaseException
*/
public function getUserByEmail(string $email): UserRecord;
/**
* @param non-empty-string $phoneNumber
*
* @throws Exception\AuthException
* @throws Exception\FirebaseException
*/
public function getUserByPhoneNumber(string $phoneNumber): UserRecord;
/**
* @param non-empty-string $providerId
* @param non-empty-string $providerUid
*
* @throws UserNotFound
* @throws Exception\AuthException
* @throws Exception\FirebaseException
*/
public function getUserByProviderUid(string $providerId, string $providerUid): UserRecord;
/**
* @throws Exception\AuthException
* @throws Exception\FirebaseException
*/
public function createAnonymousUser(): UserRecord;
/**
* @param non-empty-string $uid
* @param non-empty-string $newPassword
*
* @throws Exception\AuthException
* @throws Exception\FirebaseException
*/
public function changeUserPassword(string $uid, string $newPassword): UserRecord;
/**
* @param non-empty-string $uid
* @param non-empty-string $newEmail
*
* @throws Exception\AuthException
* @throws Exception\FirebaseException
*/
public function changeUserEmail(string $uid, string $newEmail): UserRecord;
/**
* @param non-empty-string $uid
*
* @throws Exception\AuthException
* @throws Exception\FirebaseException
*/
public function enableUser(string $uid): UserRecord;
/**
* @param non-empty-string $uid
*
* @throws Exception\AuthException
* @throws Exception\FirebaseException
*/
public function disableUser(string $uid): UserRecord;
/**
* @param non-empty-string $uid
*
* @throws UserNotFound
* @throws Exception\AuthException
* @throws Exception\FirebaseException
*/
public function deleteUser(string $uid): void;
/**
* @param iterable<non-empty-string> $uids
* @param bool $forceDeleteEnabledUsers Whether to force deleting accounts that are not in disabled state. If false, only disabled accounts will be deleted, and accounts that are not disabled will be added to the errors.
*
* @throws Exception\AuthException
*/
public function deleteUsers(iterable $uids, bool $forceDeleteEnabledUsers = false): DeleteUsersResult;
/**
* @param non-empty-string $type
* @param non-empty-string $email
* @param ActionCodeSettings|array<non-empty-string, mixed>|null $actionCodeSettings
* @param non-empty-string|null $locale
*
* @throws FailedToCreateActionLink
*/
public function getEmailActionLink(string $type, string $email, $actionCodeSettings = null, ?string $locale = null): string;
/**
* @param non-empty-string $type
* @param non-empty-string $email
* @param ActionCodeSettings|array<non-empty-string, mixed>|null $actionCodeSettings
* @param non-empty-string|null $locale
*
* @throws UserNotFound
* @throws FailedToSendActionLink
*/
public function sendEmailActionLink(string $type, string $email, $actionCodeSettings = null, ?string $locale = null): void;
/**
* @param non-empty-string $email
* @param ActionCodeSettings|array<non-empty-string, mixed>|null $actionCodeSettings
* @param non-empty-string|null $locale
*
* @throws FailedToCreateActionLink
*/
public function getEmailVerificationLink(string $email, $actionCodeSettings = null, ?string $locale = null): string;
/**
* @param non-empty-string $email
* @param ActionCodeSettings|array<non-empty-string, mixed>|null $actionCodeSettings
* @param non-empty-string|null $locale
*
* @throws FailedToSendActionLink
*/
public function sendEmailVerificationLink(string $email, $actionCodeSettings = null, ?string $locale = null): void;
/**
* @param non-empty-string $email
* @param ActionCodeSettings|array<non-empty-string, mixed>|null $actionCodeSettings
* @param non-empty-string|null $locale
*
* @throws FailedToCreateActionLink
*/
public function getPasswordResetLink(string $email, $actionCodeSettings = null, ?string $locale = null): string;
/**
* @param non-empty-string $email
* @param ActionCodeSettings|array<non-empty-string, mixed>|null $actionCodeSettings
* @param non-empty-string|null $locale
*
* @throws FailedToSendActionLink
*/
public function sendPasswordResetLink(string $email, $actionCodeSettings = null, ?string $locale = null): void;
/**
* @param non-empty-string $email
* @param ActionCodeSettings|array<non-empty-string, mixed>|null $actionCodeSettings
* @param non-empty-string|null $locale
*
* @throws FailedToCreateActionLink
*/
public function getSignInWithEmailLink(string $email, $actionCodeSettings = null, ?string $locale = null): string;
/**
* @param non-empty-string $email
* @param ActionCodeSettings|array<non-empty-string, mixed>|null $actionCodeSettings
* @param non-empty-string|null $locale
*
* @throws FailedToSendActionLink
*/
public function sendSignInWithEmailLink(string $email, $actionCodeSettings = null, ?string $locale = null): void;
/**
* Sets additional developer claims on an existing user identified by the provided UID.
*
* @see https://firebase.google.com/docs/auth/admin/custom-claims
*
* @param non-empty-string $uid
* @param array<non-empty-string, mixed>|null $claims
*
* @throws Exception\AuthException
* @throws Exception\FirebaseException
*/
public function setCustomUserClaims(string $uid, ?array $claims): void;
/**
* @param array<non-empty-string, mixed> $claims
* @param int<0, 3600>|DateInterval|non-empty-string $ttl
*
* @throws Exception\AuthException
* @throws Exception\FirebaseException
*/
public function createCustomToken(string $uid, array $claims = [], int|DateInterval|string $ttl = 3600): UnencryptedToken;
/**
* @param non-empty-string $tokenString
*/
public function parseToken(string $tokenString): UnencryptedToken;
/**
* Creates a new Firebase session cookie with the given lifetime.
*
* The session cookie JWT will have the same payload claims as the provided ID token.
*
* @param Token|non-empty-string $idToken The Firebase ID token to exchange for a session cookie
* @param DateInterval|positive-int $ttl
*
* @throws InvalidArgumentException if the token or TTL is invalid
* @throws FailedToCreateSessionCookie
*/
public function createSessionCookie(Token|string $idToken, DateInterval|int $ttl): string;
/**
* Verifies a JWT auth token.
*
* Returns a token with the token's claims or rejects it if the token could not be verified.
*
* If checkRevoked is set to true, verifies if the session corresponding to the ID token was revoked.
* If the corresponding user's session was invalidated, a RevokedIdToken exception is thrown.
* If not specified the check is not applied.
*
* NOTE: Allowing time inconsistencies might impose a security risk. Do this only when you are not able
* to fix your environment's time to be consistent with Google's servers.
*
* @param Token|non-empty-string $idToken the JWT to verify
* @param bool $checkIfRevoked whether to check if the ID token is revoked
* @param positive-int|null $leewayInSeconds number of seconds to allow a token to be expired, in case that there
* is a clock skew between the signing and the verifying server
*
* @throws FailedToVerifyToken if the token could not be verified
* @throws RevokedIdToken if the token has been revoked
*/
public function verifyIdToken(Token|string $idToken, bool $checkIfRevoked = false, ?int $leewayInSeconds = null): UnencryptedToken;
/**
* Verifies a JWT session cookie.
*
* Returns a token with the cookie's claims or rejects it if the session cookie could not be verified.
*
* If checkRevoked is set to true, verifies if the session corresponding to the ID token was revoked.
* If the corresponding user's session was invalidated, a RevokedSessionCookie exception is thrown.
* If not specified the check is not applied.
*
* NOTE: Allowing time inconsistencies might impose a security risk. Do this only when you are not able
* to fix your environment's time to be consistent with Google's servers.
*
* @param non-empty-string $sessionCookie
* @param positive-int|null $leewayInSeconds
*
* @throws FailedToVerifySessionCookie
* @throws RevokedSessionCookie
*/
public function verifySessionCookie(string $sessionCookie, bool $checkIfRevoked = false, ?int $leewayInSeconds = null): UnencryptedToken;
/**
* Verifies the given password reset code and returns the associated user's email address.
*
* @see https://firebase.google.com/docs/reference/rest/auth#section-verify-password-reset-code
*
* @param non-empty-string $oobCode
*
* @throws ExpiredOobCode
* @throws InvalidOobCode
* @throws OperationNotAllowed
* @throws Exception\AuthException
* @throws Exception\FirebaseException
*/
public function verifyPasswordResetCode(string $oobCode): string;
/**
* Applies the password reset requested via the given OOB code and returns the associated user's email address.
*
* @see https://firebase.google.com/docs/reference/rest/auth#section-confirm-reset-password
*
* @param non-empty-string $oobCode the email action code sent to the user's email for resetting the password
* @param non-empty-string $newPassword
* @param bool $invalidatePreviousSessions Invalidate sessions initialized with the previous credentials
*
* @throws ExpiredOobCode
* @throws InvalidOobCode
* @throws OperationNotAllowed
* @throws UserDisabled
* @throws Exception\AuthException
* @throws Exception\FirebaseException
*/
public function confirmPasswordReset(string $oobCode, string $newPassword, bool $invalidatePreviousSessions = true): string;
/**
* Revokes all refresh tokens for the specified user identified by the uid provided.
* In addition to revoking all refresh tokens for a user, all ID tokens issued
* before revocation will also be revoked on the Auth backend. Any request with an
* ID token generated before revocation will be rejected with a token expired error.
*
* @param string $uid the user whose tokens are to be revoked
*
* @throws Exception\AuthException
* @throws Exception\FirebaseException
*/
public function revokeRefreshTokens(string $uid): void;
/**
* @param non-empty-string $uid
* @param list<non-empty-string>|non-empty-string $provider
*
* @throws Exception\AuthException
* @throws Exception\FirebaseException
*/
public function unlinkProvider(string $uid, array|string $provider): UserRecord;
/**
* @param UserRecord|non-empty-string $user
* @param array<non-empty-string, mixed>|null $claims
*
* @throws FailedToSignIn
*/
public function signInAsUser(UserRecord|string $user, ?array $claims = null): SignInResult;
/**
* @param Token|non-empty-string $token
*
* @throws FailedToSignIn
*/
public function signInWithCustomToken(Token|string $token): SignInResult;
/**
* @param non-empty-string $refreshToken
*
* @throws FailedToSignIn
*/
public function signInWithRefreshToken(string $refreshToken): SignInResult;
/**
* @param non-empty-string $email
* @param non-empty-string $clearTextPassword
*
* @throws FailedToSignIn
*/
public function signInWithEmailAndPassword(string $email, string $clearTextPassword): SignInResult;
/**
* @param non-empty-string $email
* @param non-empty-string $oobCode
*
* @throws FailedToSignIn
*/
public function signInWithEmailAndOobCode(string $email, string $oobCode): SignInResult;
/**
* @throws FailedToSignIn
*/
public function signInAnonymously(): SignInResult;
/**
* @see https://cloud.google.com/identity-platform/docs/reference/rest/v1/accounts/signInWithIdp
*
* @param non-empty-string $provider
* @param Token|non-empty-string $accessToken
* @param non-empty-string|null $redirectUrl
* @param non-empty-string|null $oauthTokenSecret
* @param non-empty-string|null $linkingIdToken
* @param non-empty-string|null $rawNonce
*
* @throws FailedToSignIn
*/
public function signInWithIdpAccessToken(string $provider, Token|string $accessToken, ?string $redirectUrl = null, ?string $oauthTokenSecret = null, ?string $linkingIdToken = null, ?string $rawNonce = null): SignInResult;
/**
* @param non-empty-string $provider
* @param Token|non-empty-string $idToken
* @param non-empty-string|null $redirectUrl
* @param non-empty-string|null $linkingIdToken
* @param non-empty-string|null $rawNonce
*
* @throws FailedToSignIn
*/
public function signInWithIdpIdToken(string $provider, Token|string $idToken, ?string $redirectUrl = null, ?string $linkingIdToken = null, ?string $rawNonce = null): SignInResult;
}