authentik.lib.generators

ID/Secret Generators

 1"""ID/Secret Generators"""
 2
 3import string
 4from random import SystemRandom
 5
 6
 7def generate_code_fixed_length(length=9) -> str:
 8    """Generate a numeric code"""
 9    rand = SystemRandom()
10    num = rand.randrange(1, 10**length)
11    return str(num).zfill(length)
12
13
14def generate_id(length=40) -> str:
15    """Generate a random client ID"""
16    rand = SystemRandom()
17    return "".join(rand.choice(string.ascii_letters + string.digits) for x in range(length))
18
19
20def generate_key(length=128) -> str:
21    """Generate a suitable client secret"""
22    rand = SystemRandom()
23    return "".join(
24        rand.choice(string.ascii_letters + string.digits + string.punctuation)
25        for x in range(length)
26    )
def generate_code_fixed_length(length=9) -> str:
 8def generate_code_fixed_length(length=9) -> str:
 9    """Generate a numeric code"""
10    rand = SystemRandom()
11    num = rand.randrange(1, 10**length)
12    return str(num).zfill(length)

Generate a numeric code

def generate_id(length=40) -> str:
15def generate_id(length=40) -> str:
16    """Generate a random client ID"""
17    rand = SystemRandom()
18    return "".join(rand.choice(string.ascii_letters + string.digits) for x in range(length))

Generate a random client ID

def generate_key(length=128) -> str:
21def generate_key(length=128) -> str:
22    """Generate a suitable client secret"""
23    rand = SystemRandom()
24    return "".join(
25        rand.choice(string.ascii_letters + string.digits + string.punctuation)
26        for x in range(length)
27    )

Generate a suitable client secret