Skip to content

Commit 9f9a20a

Browse files
author
Ahsan Ulhaq
authored
Merge pull request #106 from edx/ahsan/Single-sign-out
Added single signout
2 parents 1022dfa + 9135dca commit 9f9a20a

File tree

4 files changed

+13
-28
lines changed

4 files changed

+13
-28
lines changed

credentials/apps/api/tests/test_views.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Tests for credentials service views.
33
"""
4+
# pylint: disable=no-member
45
from __future__ import unicode_literals
56
import json
67

@@ -31,7 +32,7 @@ def setUp(self):
3132
super(UserCredentialViewSetTests, self).setUp()
3233

3334
self.user = factories.UserFactory()
34-
self.client.force_authenticate(self.user) # pylint: disable=no-member
35+
self.client.force_authenticate(self.user)
3536

3637
self.program_cert = factories.ProgramCertificateFactory()
3738
self.program_id = self.program_cert.program_id
@@ -43,7 +44,6 @@ def setUp(self):
4344

4445
def _add_permission(self, perm):
4546
""" DRY helper to add usercredential model permissions to self.user """
46-
# pylint: disable=no-member
4747
self.user.user_permissions.add(Permission.objects.get(codename='{}_usercredential'.format(perm)))
4848

4949
def _attempt_update_user_credential(self, data):
@@ -55,7 +55,6 @@ def _attempt_update_user_credential(self, data):
5555
Returns:
5656
Response: HTTP response from the API.
5757
"""
58-
# pylint: disable=no-member
5958
self._add_permission('change')
6059
path = reverse("api:v1:usercredential-detail", args=[self.user_credential.id])
6160
return self.client.patch(path=path, data=json.dumps(data), content_type=JSON_CONTENT_TYPE)
@@ -120,7 +119,6 @@ def _attempt_create_user_credentials(self, data):
120119
Returns:
121120
Response: HTTP response from the API.
122121
"""
123-
# pylint: disable=no-member
124122
self._add_permission('add')
125123
path = self.list_path
126124
return self.client.post(path=path, data=json.dumps(data), content_type=JSON_CONTENT_TYPE)
@@ -457,7 +455,6 @@ class UserCredentialViewSetPermissionsTests(APITestCase):
457455

458456
def make_user(self, group=None, perm=None, **kwargs):
459457
""" DRY helper to create users with specific groups and/or permissions. """
460-
# pylint: disable=no-member
461458
user = factories.UserFactory(**kwargs)
462459
if group:
463460
user.groups.add(Group.objects.get(name=group))
@@ -482,7 +479,7 @@ def test_list(self, user_kwargs, expected_status):
482479
"""
483480
list_path = reverse("api:v1:usercredential-list")
484481

485-
self.client.force_authenticate(self.make_user(**user_kwargs)) # pylint: disable=no-member
482+
self.client.force_authenticate(self.make_user(**user_kwargs))
486483
response = self.client.get(list_path, {'username': 'test-user'})
487484
self.assertEqual(response.status_code, expected_status)
488485

@@ -509,7 +506,7 @@ def test_create(self, user_kwargs, expected_status):
509506
'attributes': [],
510507
}
511508

512-
self.client.force_authenticate(self.make_user(**user_kwargs)) # pylint: disable=no-member
509+
self.client.force_authenticate(self.make_user(**user_kwargs))
513510
response = self.client.post(list_path, data=json.dumps(post_data), content_type=JSON_CONTENT_TYPE)
514511
self.assertEqual(response.status_code, expected_status)
515512

@@ -533,7 +530,7 @@ def test_retrieve(self, user_kwargs, expected_status):
533530
user_credential = factories.UserCredentialFactory.create(credential=program_cert, username='test-user')
534531
detail_path = reverse("api:v1:usercredential-detail", args=[user_credential.id])
535532

536-
self.client.force_authenticate(self.make_user(**user_kwargs)) # pylint: disable=no-member
533+
self.client.force_authenticate(self.make_user(**user_kwargs))
537534
response = self.client.get(detail_path)
538535
self.assertEqual(response.status_code, expected_status)
539536

@@ -560,7 +557,7 @@ def test_partial_update(self, user_kwargs, expected_status):
560557
},
561558
'attributes': [{'name': 'dummy-attr-name', 'value': 'dummy-attr-value'}],
562559
}
563-
self.client.force_authenticate(self.make_user(**user_kwargs)) # pylint: disable=no-member
560+
self.client.force_authenticate(self.make_user(**user_kwargs))
564561
response = self.client.patch(path=detail_path, data=json.dumps(post_data), content_type=JSON_CONTENT_TYPE)
565562
self.assertEqual(response.status_code, expected_status)
566563

@@ -574,18 +571,17 @@ class CredentialViewSetTests(APITestCase):
574571
def setUp(self):
575572
super(CredentialViewSetTests, self).setUp()
576573

577-
# pylint: disable=no-member
578574
self.user = factories.UserFactory()
579575
self.user.groups.add(Group.objects.get(name=Role.ADMINS))
580-
self.client.force_authenticate(self.user) # pylint: disable=no-member
576+
self.client.force_authenticate(self.user)
581577
self.request = APIRequestFactory().get('/')
582578

583579
def assert_permission_required(self, data):
584580
"""
585581
Ensure access to these APIs is restricted to those with explicit model
586582
permissions.
587583
"""
588-
self.client.force_authenticate(user=factories.UserFactory()) # pylint: disable=no-member
584+
self.client.force_authenticate(user=factories.UserFactory())
589585
response = self.client.get(self.list_path, data)
590586
self.assertEqual(response.status_code, 403)
591587

credentials/settings/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@
230230
SOCIAL_AUTH_EDX_OIDC_KEY = 'replace-me'
231231
SOCIAL_AUTH_EDX_OIDC_SECRET = 'replace-me'
232232
SOCIAL_AUTH_EDX_OIDC_URL_ROOT = 'replace-me'
233+
SOCIAL_AUTH_EDX_OIDC_LOGOUT_URL = 'replace-me'
233234
SOCIAL_AUTH_EDX_OIDC_ID_TOKEN_DECRYPTION_KEY = SOCIAL_AUTH_EDX_OIDC_SECRET
234235

235236
# Request the user's permissions in the ID token

credentials/urls.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,25 @@
1515

1616
import os
1717

18+
from auth_backends.urls import auth_urlpatterns
1819
from django.conf import settings
1920
from django.conf.urls import include, url
2021
from django.conf.urls.static import static
2122
from django.contrib import admin
22-
from django.contrib.auth.views import logout
23-
from django.core.urlresolvers import reverse_lazy
24-
from django.views.generic import RedirectView
2523

2624
from credentials.apps.core import views as core_views
2725

2826
admin.autodiscover()
2927

30-
# pylint: disable=invalid-name
31-
# Always login via edX OpenID Connect
32-
login = RedirectView.as_view(url=reverse_lazy('social:begin', args=['edx-oidc']), permanent=False, query_string=True)
3328

34-
AUTH_URLS = [
35-
url(r'^login/$', login, name='login'),
36-
url(r'^logout/$', logout, name='logout'),
37-
]
38-
39-
urlpatterns = [
40-
url(r'^accounts/', include(AUTH_URLS)),
29+
urlpatterns = auth_urlpatterns + [
4130
url(r'^admin/', include(admin.site.urls)),
4231
url(r'^api/', include('credentials.apps.api.urls', namespace='api')),
43-
url(r'^api-auth/', include(AUTH_URLS, namespace='rest_framework')),
32+
url(r'^api-auth/', include(auth_urlpatterns, namespace='rest_framework')),
4433
url(r'^auto_auth/$', core_views.AutoAuth.as_view(), name='auto_auth'),
4534
url(r'^credentials/', include('credentials.apps.credentials.urls', namespace='credentials')),
4635
url(r'^health/$', core_views.health, name='health'),
4736
url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', ''),
48-
url('', include('social.apps.django_app.urls', namespace='social')),
4937
]
5038

5139
handler500 = 'credentials.apps.core.views.render_500'

requirements/base.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ djangorestframework==3.2.3
99
djangorestframework-jwt==1.7.2
1010
django-rest-swagger==0.3.4
1111
django-storages==1.1.8
12-
edx-auth-backends==0.2.3
12+
edx-auth-backends==0.5.0
1313
edx-drf-extensions==0.5.1
1414
edx-opaque-keys==0.3.1
1515
edx-rest-api-client==1.4.0

0 commit comments

Comments
 (0)