Gustavo, I finally got back to this but I'm having some trouble that
perhaps you could shed some light on?
So, this is what I've done as per your instructions:
in file <
myapp.config.repoze_cfg.py>:
from repoze.who.classifiers import default_request_classifier
from repoze.who.interfaces import IChallenger, IIdentifier
from repoze.who.plugins.basicauth import BasicAuthPlugin
def api_identifier(environ):
if environ.get('myapp.flex_detected',False): #<-- I have WSGI
middleware defined that is setting that flag.
return "api"
return default_request_classifier(environ)
API_AUTH_PLUGIN = BasicAuthPlugin('myapp')
API_AUTH_PLUGIN.classifications = {
IIdentifier: ["api"],
IChallenger: ["api"],
}
in file <
myapp.config.app_cfg.py>:
from myapp.config.repoze_cfg import api_identifier, API_AUTH_PLUGIN
...
#enable authentication via http Basic Auth
base_config.sa_auth.classifier = api_identifier
base_config.sa_auth.identifiers = [API_AUTH_PLUGIN.classifications]
#<-- trouble here...
base_config.sa_auth.challengers = [API_AUTH_PLUGIN.classifications]
#<-- trouble here...
At first, I tried setting base_config.sa_auth.identifiers as you had
outlined below with:
base_config.sa_auth.identifiers = [API_AUTH_PLUGIN]
but upon starting up TG, I would get:
"TypeError: 'BasicAuthPlugin' object is not iterable"
which was failing at
repoze.who.middleware.py in the make_registries
function. So, I then tried changing it as I've outlined above thinking
that's what the "for name, value in supplied" loop was actually
looking for...when I do that, I now get the following exception
thrown....
repoze/who/middleware.py", line 416, in make_registries
raise ValueError(str(name) + ': ' + why)
ValueError: <InterfaceClass repoze.who.interfaces.IIdentifier>: An
object has failed to implement interface <InterfaceClass
repoze.who.interfaces.IIdentifier>
The identify attribute was not provided.
When I looked at repoze.who.interfaces at the IIdentifier interface,
it looked to me like you might need to specify an identify, remember
and forget function for it to pass this test. Am I on the right track?
If so, I'm not clear on what I'm supposed to be doing in those
functions.
In your example, you marked the section that said:
API_AUTH_PLUGIN.classifications = {
IIdentifier: ["api"],
IChallenger: ["api"],
}
as optional. Why is that optional? The reason I ask is that if I
comment out like this:
base_config.sa_auth.classifier = api_identifier
#base_config.sa_auth.identifiers = [API_AUTH_PLUGIN.classifications]
#base_config.sa_auth.challengers = [API_AUTH_PLUGIN.classifications]
then the application starts up with no errors, but I'm not sure that
I'm going to get the desired effect or if I'm missing something vital
by doing that. Can you elaborate on what the
API_AUTH_PLUGIN.classifications is trying to accomplish or point me to
relevant documentation?
Thanks!