Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hand RepozeWho1AuthenticationPolicy.remember kwargs to repoze.who (master) #1249 #1254

Merged
merged 1 commit into from
Mar 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pyramid/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,19 @@ def effective_principals(self, request):
return effective_principals

def remember(self, request, principal, **kw):
""" Store the ``principal`` as ``repoze.who.userid``."""
""" Store the ``principal`` as ``repoze.who.userid``.

The identity to authenticated to :mod:`repoze.who`
will contain the given principal as ``userid``, and
provide all keyword arguments as additional identity
keys. Useful keys could be ``max_age`` or ``userdata``.
"""
identifier = self._get_identifier(request)
if identifier is None:
return []
environ = request.environ
identity = {'repoze.who.userid':principal}
identity = kw
identity['repoze.who.userid'] = principal
return identifier.remember(environ, identity)

def forget(self, request):
Expand Down
8 changes: 8 additions & 0 deletions pyramid/tests/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,14 @@ def test_remember(self):
self.assertEqual(result[0], request.environ)
self.assertEqual(result[1], {'repoze.who.userid':'fred'})

def test_remember_kwargs(self):
authtkt = DummyWhoPlugin()
request = DummyRequest(
{'repoze.who.plugins':{'auth_tkt':authtkt}})
policy = self._makeOne()
result = policy.remember(request, 'fred', max_age=23)
self.assertEqual(result[1], {'repoze.who.userid':'fred', 'max_age': 23})

def test_forget_no_plugins(self):
request = DummyRequest({})
policy = self._makeOne()
Expand Down