3
# Copyright (C) 2005 Matthew Good <trac@matt-good.net>
5
# "THE BEER-WARE LICENSE" (Revision 42):
6
# <trac@matt-good.net> wrote this file. As long as you retain this notice you
7
# can do whatever you want with this stuff. If we meet some day, and you think
8
# this stuff is worth it, you can buy me a beer in return. Matthew Good
10
# Author: Matthew Good <trac@matt-good.net>
12
from urllib2 import build_opener, HTTPBasicAuthHandler, \
13
HTTPDigestAuthHandler, HTTPPasswordMgrWithDefaultRealm
15
from trac.core import *
16
from trac.config import Option
18
from api import IPasswordStore
20
class HttpAuthStore(Component):
21
implements(IPasswordStore)
23
auth_url = Option('account-manager', 'authentication_url')
25
def check_password(self, user, password):
26
mgr = HTTPPasswordMgrWithDefaultRealm()
27
mgr.add_password(None, self.auth_url, user, password)
29
build_opener(HTTPBasicAuthHandler(mgr),
30
HTTPDigestAuthHandler(mgr)).open(self.auth_url)