Skip to content

Commit

Permalink
Allow for logout redirect with EdXOAuth2 backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Hall committed Oct 25, 2018
1 parent 0d478be commit b63b832
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion auth_backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
These package is designed to be used primarily with Open edX Django projects, but should be compatible with non-edX
projects as well.
"""
__version__ = '1.1.5' # pragma: no cover
__version__ = '1.2.0' # pragma: no cover
13 changes: 12 additions & 1 deletion auth_backends/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,18 @@ class EdXOAuth2(EdXBackendMixin, BaseOAuth2):

@property
def logout_url(self):
return self.end_session_url()
params = {
'client_id': self.setting('KEY'),
}

redirect_url = self.setting('LOGOUT_REDIRECT_URL')
if redirect_url:
params.update({'redirect_url': redirect_url})

return '{}?{}'.format(
self.end_session_url(),
six.moves.urllib.parse.urlencode(params),
)

def authorization_url(self):
return '{}/oauth2/authorize'.format(self.setting('URL_ROOT'))
Expand Down
13 changes: 12 additions & 1 deletion auth_backends/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class EdXOAuth2Tests(OAuth2Test):
client_secret = 'a-secret-key'
expected_username = 'jsmith'
url_root = 'https://example.com'
logout_redirect_url = 'https://example.com/logout_redirect'

def setUp(self):
cache.clear()
Expand Down Expand Up @@ -243,6 +244,7 @@ def extra_settings(self):
'SOCIAL_AUTH_{0}_KEY'.format(self.name): self.client_key,
'SOCIAL_AUTH_{0}_SECRET'.format(self.name): self.client_secret,
'SOCIAL_AUTH_{0}_URL_ROOT'.format(self.name): self.url_root,
'SOCIAL_AUTH_{0}_LOGOUT_REDIRECT_URL'.format(self.name): self.logout_redirect_url,
})
return settings

Expand All @@ -254,7 +256,16 @@ def test_partial_pipeline(self):

def test_logout_url(self):
""" The property should return the provider's logout URL. """
self.assertEqual(self.backend.logout_url, '{}/logout'.format(self.url_root))
self.assertEqual(
self.backend.logout_url,
'{}/logout?{}'.format(
self.url_root,
six.moves.urllib.parse.urlencode({
'client_id': self.client_key,
'redirect_url': self.logout_redirect_url,
})
)
)

def test_end_session_url(self):
""" The method should return the provider's logout URL. """
Expand Down

0 comments on commit b63b832

Please sign in to comment.