Add a logout method to the API for application convenience.
| | |
| | | After 2.0a3 (unreleased) |
| | | ------------------------ |
| | | |
| | | - Added a ``login`` method to the ``repoze.who.api.API`` object, as a |
| | | convenience for application-driven login code, which would |
| | | - Add ``login`` and ``logout`` methods to the ``repoze.who.api.API`` object, |
| | | as a convenience for application-driven login / logout code, which would |
| | | otherwise need to use private methods of the API, and reach down into |
| | | its plugins. |
| | | |
| | |
| | | headers = identifier.forget(self.environ, None) |
| | | return None, headers |
| | | |
| | | def logout(self, identifier_name=None): |
| | | """ See IAPI. |
| | | """ |
| | | if identifier_name is not None: |
| | | identifier = self.name_registry[identifier_name] |
| | | else: |
| | | identifier = self.identifiers[0][1] |
| | | # Pretend that the given identifier extracted the identity. |
| | | return identifier.forget(self.environ, None) |
| | | |
| | | def _identify(self): |
| | | """ See IAPI. |
| | | """ |
| | |
| | | "forget" headers. |
| | | """ |
| | | |
| | | def logout(identifier_name=None): |
| | | """ -> (headers) |
| | | |
| | | o This is an API for browser-based application logout. |
| | | |
| | | o If 'identifier_name' is passed, use it to look up the identifier; |
| | | othewise, use the first configured identifier. |
| | | |
| | | o Returned headers will be "forget" headers. |
| | | """ |
| | | |
| | | |
| | | class IPlugin(Interface): |
| | | pass |
| | |
| | | self.assertEqual(headers, FORGET_HEADERS) |
| | | |
| | | def test_login_wo_identifier_name_miss(self): |
| | | FORGET_HEADERS = [('Spam', 'Blah')] |
| | | class _Identifier: |
| | | def identify(self, environ): |
| | | pass |
| | | def remember(self, environ, identity): |
| | | pass |
| | | def forget(self, environ, identity): |
| | | return FORGET_HEADERS |
| | | class _BogusIdentifier: |
| | | def identify(self, environ): |
| | | pass |
| | | def remember(self, environ, identity): |
| | | pass |
| | | def forget(self, environ, identity): |
| | | pass |
| | | environ = self._makeEnviron() |
| | | identifiers = [('valid', _Identifier()), |
| | | ('bogus', _BogusIdentifier()), |
| | | ] |
| | | api = self._makeOne(identifiers=identifiers, |
| | | environ=environ) |
| | | headers = api.logout() |
| | | self.assertEqual(headers, FORGET_HEADERS) |
| | | |
| | | def test_logout_w_identifier_name(self): |
| | | FORGET_HEADERS = [('Spam', 'Blah')] |
| | | class _Identifier: |
| | | def identify(self, environ): |
| | | pass |
| | | def remember(self, environ, identity): |
| | | pass |
| | | def forget(self, environ, identity): |
| | | return FORGET_HEADERS |
| | | class _BogusIdentifier: |
| | | def identify(self, environ): |
| | | pass |
| | | def remember(self, environ, identity): |
| | | pass |
| | | def forget(self, environ, identity): |
| | | pass |
| | | environ = self._makeEnviron() |
| | | identifiers = [('bogus', _BogusIdentifier()), |
| | | ('valid', _Identifier()), |
| | | ] |
| | | api = self._makeOne(identifiers=identifiers, |
| | | environ=environ) |
| | | headers = api.logout('valid') |
| | | self.assertEqual(headers, FORGET_HEADERS) |
| | | |
| | | def test_logout_wo_identifier_name(self): |
| | | REMEMBER_HEADERS = [('Foo', 'Bar'), ('Baz', 'Qux')] |
| | | FORGET_HEADERS = [('Spam', 'Blah')] |
| | | class _Identifier: |