@@ -27,7 +27,7 @@ def b64_encode(bytes_value):
27
27
class UserProvider (object ):
28
28
"""Represents a user identity provider that can be associated with a Firebase user.
29
29
30
- One or more providers can be specified in a ``UserImportRecord `` when importing users via
30
+ One or more providers can be specified in an ``ImportUserRecord `` when importing users via
31
31
``auth.import_users()``.
32
32
33
33
Args:
@@ -97,10 +97,10 @@ def to_dict(self):
97
97
return {k : v for k , v in payload .items () if v is not None }
98
98
99
99
100
- class UserImportRecord (object ):
100
+ class ImportUserRecord (object ):
101
101
"""Represents a user account to be imported to Firebase Auth.
102
102
103
- Must specify the ``uid`` field at a minimum. A sequence of ``UserImportRecord `` objects can be
103
+ Must specify the ``uid`` field at a minimum. A sequence of ``ImportUserRecord `` objects can be
104
104
passed to the ``auth.import_users()`` function, in order to import those users into Firebase
105
105
Auth in bulk. If the ``password_hash`` is set on a user, a hash configuration must be
106
106
specified when calling ``import_users()``.
@@ -259,7 +259,10 @@ class UserImportHash(object):
259
259
"""Represents a hash algorithm used to hash user passwords.
260
260
261
261
An instance of this class must be specified when importing users with passwords via the
262
- ``auth.import_users()`` API.
262
+ ``auth.import_users()`` API. Use one of the provided class methods to obtain new
263
+ instances when required. Refer to `documentation`_ for more details.
264
+
265
+ .. _documentation: https://firebase.google.com/docs/auth/admin/import-users
263
266
"""
264
267
265
268
def __init__ (self , name , data = None ):
@@ -298,42 +301,128 @@ def hmac_sha512(cls, key):
298
301
299
302
@classmethod
300
303
def hmac_sha256 (cls , key ):
304
+ """Creates a new HMAC SHA256 algorithm instance.
305
+
306
+ Args:
307
+ key: Signer key as a byte sequence.
308
+
309
+ Returns:
310
+ UserImportHash: A new ``UserImportHash``.
311
+ """
301
312
return cls ._hmac ('HMAC_SHA256' , key )
302
313
303
314
@classmethod
304
315
def hmac_sha1 (cls , key ):
316
+ """Creates a new HMAC SHA1 algorithm instance.
317
+
318
+ Args:
319
+ key: Signer key as a byte sequence.
320
+
321
+ Returns:
322
+ UserImportHash: A new ``UserImportHash``.
323
+ """
305
324
return cls ._hmac ('HMAC_SHA1' , key )
306
325
307
326
@classmethod
308
327
def hmac_md5 (cls , key ):
328
+ """Creates a new HMAC MD5 algorithm instance.
329
+
330
+ Args:
331
+ key: Signer key as a byte sequence.
332
+
333
+ Returns:
334
+ UserImportHash: A new ``UserImportHash``.
335
+ """
309
336
return cls ._hmac ('HMAC_MD5' , key )
310
337
311
338
@classmethod
312
339
def md5 (cls , rounds ):
340
+ """Creates a new MD5 algorithm instance.
341
+
342
+ Args:
343
+ rounds: Number of rounds. Must be an integer between 0 and 120000.
344
+
345
+ Returns:
346
+ UserImportHash: A new ``UserImportHash``.
347
+ """
313
348
return cls ._basic_hash ('MD5' , rounds )
314
349
315
350
@classmethod
316
351
def sha1 (cls , rounds ):
352
+ """Creates a new SHA1 algorithm instance.
353
+
354
+ Args:
355
+ rounds: Number of rounds. Must be an integer between 0 and 120000.
356
+
357
+ Returns:
358
+ UserImportHash: A new ``UserImportHash``.
359
+ """
317
360
return cls ._basic_hash ('SHA1' , rounds )
318
361
319
362
@classmethod
320
363
def sha256 (cls , rounds ):
364
+ """Creates a new SHA256 algorithm instance.
365
+
366
+ Args:
367
+ rounds: Number of rounds. Must be an integer between 0 and 120000.
368
+
369
+ Returns:
370
+ UserImportHash: A new ``UserImportHash``.
371
+ """
321
372
return cls ._basic_hash ('SHA256' , rounds )
322
373
323
374
@classmethod
324
375
def sha512 (cls , rounds ):
376
+ """Creates a new SHA512 algorithm instance.
377
+
378
+ Args:
379
+ rounds: Number of rounds. Must be an integer between 0 and 120000.
380
+
381
+ Returns:
382
+ UserImportHash: A new ``UserImportHash``.
383
+ """
325
384
return cls ._basic_hash ('SHA512' , rounds )
326
385
327
386
@classmethod
328
387
def pbkdf_sha1 (cls , rounds ):
388
+ """Creates a new PBKDF SHA1 algorithm instance.
389
+
390
+ Args:
391
+ rounds: Number of rounds. Must be an integer between 0 and 120000.
392
+
393
+ Returns:
394
+ UserImportHash: A new ``UserImportHash``.
395
+ """
329
396
return cls ._basic_hash ('PBKDF_SHA1' , rounds )
330
397
331
398
@classmethod
332
- def pbkdf_sha256 (cls , rounds ):
399
+ def pbkdf2_sha256 (cls , rounds ):
400
+ """Creates a new PBKDF2 SHA256 algorithm instance.
401
+
402
+ Args:
403
+ rounds: Number of rounds. Must be an integer between 0 and 120000.
404
+
405
+ Returns:
406
+ UserImportHash: A new ``UserImportHash``.
407
+ """
333
408
return cls ._basic_hash ('PBKDF2_SHA256' , rounds )
334
409
335
410
@classmethod
336
411
def scrypt (cls , key , rounds , memory_cost , salt_separator = None ):
412
+ """Creates a new Scrypt algorithm instance.
413
+
414
+ This is the modified Scrypt algorithm used by Firebase Auth. See ``standard_scrypt()``
415
+ function for the standard Scrypt algorith,
416
+
417
+ Args:
418
+ key: Signer key as a byte sequence.
419
+ rounds: Number of rounds. Must be an integer between 1 and 8.
420
+ memory_cost: Memory cost as an integer between 1 and 14.
421
+ salt_separator: Salt separator as a byte sequence (optional).
422
+
423
+ Returns:
424
+ UserImportHash: A new ``UserImportHash``.
425
+ """
337
426
data = {
338
427
'signerKey' : b64_encode (_auth_utils .validate_bytes (key , 'key' , required = True )),
339
428
'rounds' : _auth_utils .validate_int (rounds , 'rounds' , 1 , 8 ),
@@ -346,10 +435,26 @@ def scrypt(cls, key, rounds, memory_cost, salt_separator=None):
346
435
347
436
@classmethod
348
437
def bcrypt (cls ):
438
+ """Creates a new Bcrypt algorithm instance.
439
+
440
+ Returns:
441
+ UserImportHash: A new ``UserImportHash``.
442
+ """
349
443
return UserImportHash ('BCRYPT' )
350
444
351
445
@classmethod
352
446
def standard_scrypt (cls , memory_cost , parallelization , block_size , derived_key_length ):
447
+ """Creates a new standard Scrypt algorithm instance.
448
+
449
+ Args:
450
+ memory_cost: Memory cost as a non-negaive integer.
451
+ parallelization: Parallelization as a non-negative integer.
452
+ block_size: Block size as a non-negative integer.
453
+ derived_key_length: Derived key length as a non-negative integer.
454
+
455
+ Returns:
456
+ UserImportHash: A new ``UserImportHash``.
457
+ """
353
458
data = {
354
459
'memoryCost' : _auth_utils .validate_int (memory_cost , 'memory_cost' , low = 0 ),
355
460
'parallelization' : _auth_utils .validate_int (parallelization , 'parallelization' , low = 0 ),
@@ -360,7 +465,7 @@ def standard_scrypt(cls, memory_cost, parallelization, block_size, derived_key_l
360
465
361
466
362
467
class ErrorInfo (object ):
363
- """Represents an error encountered while importing a ``UserImportRecord ``."""
468
+ """Represents an error encountered while importing an ``ImportUserRecord ``."""
364
469
365
470
def __init__ (self , error ):
366
471
self ._index = error ['index' ]
0 commit comments