def generate_user_totp(ctx, directory_id, user_identifier): """DIRECTORY_ID USER_IDENTIFIER""" client = get_directory_client(directory_id, ctx.obj['factory']) response = client.generate_user_totp(user_identifier) print_result("TOTP Generated for User", { "Algorithm": response.algorithm, "Digits": response.digits, "Period": response.period, "Secret": response.secret }, color=SUCCESS_COLOR) provisioning_uri = \ f"otpauth://totp/LaunchKey%20Test%20TOTP:{user_identifier}?" \ f"digits={response.digits}" \ f"&secret={response.secret}" \ f"&algorithm={response.algorithm}" \ f"&period={response.period}" \ f"&issuer=LaunchKey+Test+TOTP" qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_Q, box_size=10, border=4, ) qr.add_data(provisioning_uri) qr.make(fit=True) qr.print_ascii()
def device_link(ctx, directory_id, user_identifier, ttl): """DIRECTORY_ID USER_IDENTIFIER""" client = get_directory_client(directory_id, ctx.obj['factory']) kwargs = {} if ttl is not None: kwargs['ttl'] = ttl link_response = client.link_device(user_identifier, **kwargs) print_result("Device link request successful", { "QR Code URL": link_response.qrcode, "Linking code": link_response.code, "Device ID": link_response.device_id }, color=SUCCESS_COLOR)
def devices_list(ctx, directory_id, user_identifier): """DIRECTORY_ID USER_IDENTIFIER""" client = get_directory_client(directory_id, ctx.obj['factory']) devices = client.get_linked_devices(user_identifier) if devices: for device in devices: print_result( device.name if device.name else "Pending Device", { "ID": device.id, "Type": device.type if device.type else "N/A", "Status": device.status.status_code }) else: click.secho("No devices found for the given identifier.", fg=FAILURE_COLOR)
def device_unlink(ctx, directory_id, user_identifier, device_identifier): """DIRECTORY_ID USER_IDENTIFIER DEVICE_IDENTIFIER""" client = get_directory_client(directory_id, ctx.obj['factory']) client.unlink_device(user_identifier, device_identifier) click.secho("Device unlinked", fg=SUCCESS_COLOR)
def remove_user_totp(ctx, directory_id, user_identifier): """DIRECTORY_ID USER_IDENTIFIER""" client = get_directory_client(directory_id, ctx.obj['factory']) client.remove_user_totp(user_identifier) click.secho("TOTP configuration removed from user", fg=SUCCESS_COLOR)