ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
814 stars 1.49k forks source link

keycloak_realm: Configure OTP #4614

Open Nannymeta opened 2 years ago

Nannymeta commented 2 years ago

Summary

Add configure OTP parameter as a required action on keycloak_realm.py.

This would be great because today it's a manual action. It's already working for verify email option.

image

Issue Type

Feature Idea

Component Name

keycloak_realm

Additional Information

Code of Conduct

ansibullbot commented 2 years ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot commented 2 years ago

cc @eikef @kris2kris @ndclt click here for bot help

ansibullbot commented 1 year ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot commented 1 year ago

cc @mattock click here for bot help

DJUL45 commented 1 year ago

import pyotp import telegram from telegram.ext import Updater, MessageHandler, Filters

Token du bot Telegram

TOKEN = 'votre_token'

Création de l'objet Updater et connexion avec Telegram

updater = Updater(token=TOKEN, use_context=True) dispatcher = updater.dispatcher

Fonction pour générer un secret key de Google Authenticator

def generate_google_secret_key(): return pyotp.random_base32()

Fonction pour générer un code à 6 chiffres à partir du secret key de Google Authenticator

def generate_google_code(secret_key): totp = pyotp.TOTP(secret_key) return totp.now()

Fonction pour générer un secret key d'Instagram

def generate_instagram_secret_key(): return pyotp.random_base32(length=32)

Fonction pour générer un code à 6 chiffres à partir du secret key d'Instagram

def generate_instagram_code(secret_key): totp = pyotp.TOTP(secret_key, digits=8) return totp.now()

Fonction pour envoyer un code OTP sur Telegram

def send_otp(chat_id, code, service): updater.bot.send_message(chat_id=chat_id, text=f"Votre code OTP {service} est: {code}")

Gestionnaire de message pour générer et envoyer un code OTP

def handle_message(update, context): chat_id = update.effective_chat.id

# Générer le secret key et le code Google Authenticator
google_secret_key = generate_google_secret_key()
google_code = generate_google_code(google_secret_key)

# Générer le secret key et le code Instagram
instagram_secret_key = generate_instagram_secret_key()
instagram_code = generate_instagram_code(instagram_secret_key)

# Envoyer les codes OTP sur Telegram
send_otp(chat_id, google_code, 'Google')
send_otp(chat_id, instagram_code, 'Instagram')

Ajouter un gestionnaire de message pour les messages texte

dispatcher.add_handler(MessageHandler(Filters.text, handle_message))

Démarrer le bot

updater.start_polling() updater.idle()

ansibullbot commented 1 month ago

cc @thomasbach-dev click here for bot help