File tree Expand file tree Collapse file tree 2 files changed +74
-0
lines changed Expand file tree Collapse file tree 2 files changed +74
-0
lines changed Original file line number Diff line number Diff line change
1
+ from .base import AuthenticationBase
2
+
3
+
4
+ class Logout (AuthenticationBase ):
5
+
6
+ """Logout Endpoint
7
+
8
+ Args:
9
+ domain (str): Your auth0 domain (e.g: username.auth0.com)
10
+ """
11
+
12
+ def __init__ (self , domain ):
13
+ self .domain = domain
14
+
15
+ def logout (self , client_id , return_to , federated = False ):
16
+ """Logout
17
+
18
+ Use this endpoint to logout a user. If you want to navigate the user to a
19
+ specific URL after the logout, set that URL at the returnTo parameter.
20
+ The URL should be included in any the appropriate Allowed Logout URLs list:
21
+
22
+ Args:
23
+ client_id (str): The client_id of your client.
24
+
25
+ returnTo (str): URL to redirect the user after the logout.
26
+
27
+ federated (bool): Querystring parameter to log the user out of the IdP
28
+ """
29
+ if federated is True :
30
+ return self .get (
31
+ 'https://%s/v2/logout?federated&%s&%s' % (self .domain , client_id , return_to ),
32
+ headers = {'Content-Type' : 'application/json' }
33
+ )
34
+ return self .get (
35
+ 'https://%s/v2/logout?%s&%s' % (self .domain , client_id , return_to ),
36
+ headers = {'Content-Type' : 'application/json' }
37
+ )
Original file line number Diff line number Diff line change
1
+ import unittest
2
+ import mock
3
+ from ...authentication .logout import Logout
4
+
5
+
6
+ class TestLogout (unittest .TestCase ):
7
+
8
+ @mock .patch ('auth0.v3.authentication.logout.Logout.get' )
9
+ def test_logout (self , mock_get ):
10
+
11
+ g = Logout ('my.domain.com' )
12
+
13
+ g .logout (client_id = 'cid' ,
14
+ return_to = 'rto' )
15
+
16
+ args , kwargs = mock_get .call_args
17
+
18
+ self .assertEqual (args [0 ], 'https://my.domain.com/v2/logout&cid&rto' )
19
+ self .assertEqual (kwargs ['headers' ], {
20
+ 'Content-Type' : 'application/json'
21
+ })
22
+
23
+ @mock .patch ('auth0.v3.authentication.logout.Logout.get' )
24
+ def test_logout_federated (self , mock_get ):
25
+
26
+ g = Logout ('my.domain.com' )
27
+
28
+ g .logout (client_id = 'cid' ,
29
+ return_to = 'rto' ,
30
+ federated = True )
31
+
32
+ args , kwargs = mock_get .call_args
33
+
34
+ self .assertEqual (args [0 ], 'https://my.domain.com/v2/logout?federated&cid%rto' )
35
+ self .assertEqual (kwargs ['headers' ], {
36
+ 'Content-Type' : 'application/json'
37
+ })
You can’t perform that action at this time.
0 commit comments