8ed2f7fe9e
* start device flow Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * web: fix inconsistent app filtering Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * add tenant device code flow Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * add throttling to device code view Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * somewhat unrelated changes Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * add initial device code entry flow Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * add finish stage Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * it works Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * add support for verification_uri_complete Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * add some tests Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * add more tests Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * add docs Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
26 lines
697 B
Python
26 lines
697 B
Python
"""ID/Secret Generators"""
|
|
import string
|
|
from random import SystemRandom
|
|
|
|
|
|
def generate_code_fixed_length(length=9) -> str:
|
|
"""Generate a numeric code"""
|
|
rand = SystemRandom()
|
|
num = rand.randrange(1, 10**length)
|
|
return str(num).zfill(length)
|
|
|
|
|
|
def generate_id(length=40) -> str:
|
|
"""Generate a random client ID"""
|
|
rand = SystemRandom()
|
|
return "".join(rand.choice(string.ascii_letters + string.digits) for x in range(length))
|
|
|
|
|
|
def generate_key(length=128) -> str:
|
|
"""Generate a suitable client secret"""
|
|
rand = SystemRandom()
|
|
return "".join(
|
|
rand.choice(string.ascii_letters + string.digits + string.punctuation)
|
|
for x in range(length)
|
|
)
|