I'm building an application and one of the packages manage multiple auth methods.
Now it supports LDAP and PAM but I want in the future it supports a few more.
I have a package with
PAM.py
and
LDAP.py
for example PAM.py contents:
import pam
class pam_auth:
def __init__(self, username=None, password=None):
self.username=username
self.password=password
def login(self):
res_auth=pam.authenticate(username=self.username, password=password)
return res_auth
and in another package I have the next class Login:
class Login:
def __init__(self,method=None):
self.authmethod=method
def login(self):
res_login=self.authmethod.login()
return res_login
Now i'm building my auth code like:
p=pam_auth()
p.username="pep"
p.password="just"
l=Login(method=p)
print l.login
And I believe that it is not the best way to do it, and thinking in multiples and different methods to auth. For Example may be something like?:
l=Login(method=PAM.pam_auth)
l.username="pep"
l.password="just"
print l.login()
¿What is that I must change in Login Class or PAM class to work in this way?