#!/usr/bin/env pluginwrapper3
import requests
from safeguard.sessions.plugin import AAPlugin, AAResponse
from safeguard.sessions.plugin.mfa_client import MFAClient
class AcmePlugin(AAPlugin):
def do_authenticate(self):
# Glue code to instantiate and execute an MFAClient
client = AcmeClient.from_config(self.plugin_configuration)
return client.execute_authenticate(self.username, self.mfa_identity, self.mfa_password)
class AcmeClient(MFAClient):
def __init__(self, disable_echo, ignore_connection_error, server_url, token):
super().__init__('ACME plugin', ignore_connection_error)
self.disable_echo = disable_echo
self.server_url = server_url
self.token = token
@classmethod
def from_config(cls, plugin_configuration, section='acme')
# It is good practice to handle the plugin configuration in its own method.
# This method will return an instance of AcmeClient
return cls(
# In case the client needs to ask for further password(s), it should set disable_echo like AAPlugin
plugin_configuration.getboolean('auth', 'disable_echo', default=False),
plugin_configuration.getboolean(section, 'ignore_connection_error', default=False),
plugin_configuration.get(section, 'server_url'),
plugin_configuration.get(section, 'token'),
)
def push_authenticate(self, mfa_identity):
# Use the requests module to implement the HTTP/REST communication
# for push notification,
# Should return True/False depending on the outcome.
return False
def otp_authenticate(self, mfa_identity, otp):
# Use the requests module to implement the HTTP/REST communication
# for one-time password authentication.
# Should return True/False depending on the outcome.
return False