From 1766c2d175196872a81b6b62dbec3cbe8eed31fc Mon Sep 17 00:00:00 2001 From: Seth House Date: Wed, 20 Mar 2013 15:04:51 -0600 Subject: [PATCH] Added /logout URL Fixes #64 --- saltapi/netapi/rest_cherrypy/app.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/saltapi/netapi/rest_cherrypy/app.py b/saltapi/netapi/rest_cherrypy/app.py index 022614057e..496449c18c 100644 --- a/saltapi/netapi/rest_cherrypy/app.py +++ b/saltapi/netapi/rest_cherrypy/app.py @@ -164,7 +164,7 @@ def salt_auth_tool(): Redirect all unauthenticated requests to the login page ''' # Short-circuit for the login page - ignore_urls = ('/login',) + ignore_urls = ('/login', '/logout') if cherrypy.request.path_info.startswith(ignore_urls): return @@ -805,6 +805,19 @@ class Login(LowDataAdapter): }} +class Logout(LowDataAdapter): + def POST(self, **kwargs): + ''' + Destroy the currently active session and expire the session + cookie + ''' + cherrypy.lib.sessions.expire() + cherrypy.session.clear() + cherrypy.session.clean_up() + + return {'return': "Your token has been cleared"} + + class API(object): ''' Collect configuration and URL map for building the CherryPy app @@ -812,6 +825,7 @@ class API(object): url_map = { 'index': LowDataAdapter, 'login': Login, + 'logout': Logout, 'minions': Minions, 'jobs': Jobs, }