Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
586c2375
Commit
586c2375
authored
Aug 14, 2015
by
Braden MacDonald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for Twitter compatibility
parent
5d269381
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
6 deletions
+63
-6
common/djangoapps/third_party_auth/models.py
+4
-3
common/djangoapps/third_party_auth/strategy.py
+3
-3
common/djangoapps/third_party_auth/tests/specs/test_twitter.py
+45
-0
common/djangoapps/third_party_auth/tests/testutil.py
+10
-0
lms/envs/test.py
+1
-0
No files found.
common/djangoapps/third_party_auth/models.py
View file @
586c2375
...
...
@@ -12,7 +12,7 @@ from django.utils.translation import ugettext_lazy as _
import
json
import
logging
from
social.backends.base
import
BaseAuth
from
social.backends.oauth
import
BaseOAuth2
from
social.backends.oauth
import
OAuthAuth
from
social.backends.saml
import
SAMLAuth
,
SAMLIdentityProvider
from
social.exceptions
import
SocialAuthBaseException
from
social.utils
import
module_member
...
...
@@ -30,7 +30,7 @@ def _load_backend_classes(base_class=BaseAuth):
if
issubclass
(
auth_class
,
base_class
):
yield
auth_class
_PSA_BACKENDS
=
{
backend_class
.
name
:
backend_class
for
backend_class
in
_load_backend_classes
()}
_PSA_OAUTH2_BACKENDS
=
[
backend_class
.
name
for
backend_class
in
_load_backend_classes
(
BaseOAuth2
)]
_PSA_OAUTH2_BACKENDS
=
[
backend_class
.
name
for
backend_class
in
_load_backend_classes
(
OAuthAuth
)]
_PSA_SAML_BACKENDS
=
[
backend_class
.
name
for
backend_class
in
_load_backend_classes
(
SAMLAuth
)]
...
...
@@ -166,6 +166,7 @@ class ProviderConfig(ConfigurationModel):
class
OAuth2ProviderConfig
(
ProviderConfig
):
"""
Configuration Entry for an OAuth2 based provider.
Also works for OAuth1 providers.
"""
prefix
=
'oa2'
KEY_FIELDS
=
(
'backend_name'
,
)
# Backend name is unique
...
...
@@ -191,7 +192,7 @@ class OAuth2ProviderConfig(ProviderConfig):
other_settings
=
models
.
TextField
(
blank
=
True
,
help_text
=
"Optional JSON object with advanced settings, if any."
)
class
Meta
(
object
):
# pylint: disable=missing-docstring
verbose_name
=
"Provider Configuration (OAuth
2
)"
verbose_name
=
"Provider Configuration (OAuth)"
verbose_name_plural
=
verbose_name
def
clean
(
self
):
...
...
common/djangoapps/third_party_auth/strategy.py
View file @
586c2375
...
...
@@ -3,7 +3,7 @@ A custom Strategy for python-social-auth that allows us to fetch configuration f
ConfigurationModels rather than django.settings
"""
from
.models
import
OAuth2ProviderConfig
from
social.backends.oauth
import
BaseOAuth2
from
social.backends.oauth
import
OAuthAuth
from
social.strategies.django_strategy
import
DjangoStrategy
...
...
@@ -17,11 +17,11 @@ class ConfigurationModelStrategy(DjangoStrategy):
Load the setting from a ConfigurationModel if possible, or fall back to the normal
Django settings lookup.
BaseOAuth2
subclasses will call this method for every setting they want to look up.
OAuthAuth
subclasses will call this method for every setting they want to look up.
SAMLAuthBackend subclasses will call this method only after first checking if the
setting 'name' is configured via SAMLProviderConfig.
"""
if
isinstance
(
backend
,
BaseOAuth2
):
if
isinstance
(
backend
,
OAuthAuth
):
provider_config
=
OAuth2ProviderConfig
.
current
(
backend
.
name
)
if
not
provider_config
.
enabled
:
raise
Exception
(
"Can't fetch setting of a disabled backend/provider."
)
...
...
common/djangoapps/third_party_auth/tests/specs/test_twitter.py
0 → 100644
View file @
586c2375
"""
Separate integration test for Twitter which is an OAuth1 provider.
"""
from
mock
import
patch
from
third_party_auth.tests.specs
import
base
class
TwitterIntegrationTest
(
base
.
Oauth2IntegrationTest
):
"""Integration tests for Twitter backend."""
def
setUp
(
self
):
super
(
TwitterIntegrationTest
,
self
)
.
setUp
()
self
.
provider
=
self
.
configure_twitter_provider
(
enabled
=
True
,
key
=
'twitter_oauth1_key'
,
secret
=
'twitter_oauth1_secret'
,
)
# To test an OAuth1 provider, we need to patch an additional method:
patcher
=
patch
(
'social.backends.twitter.TwitterOAuth.unauthorized_token'
,
create
=
True
,
return_value
=
"unauth_token"
)
patcher
.
start
()
self
.
addCleanup
(
patcher
.
stop
)
TOKEN_RESPONSE_DATA
=
{
'access_token'
:
'access_token_value'
,
'token_type'
:
'bearer'
,
}
USER_RESPONSE_DATA
=
{
'id'
:
10101010
,
'name'
:
'Bob Loblaw'
,
'description'
:
'A Twitter User'
,
'screen_name'
:
'bobloblaw'
,
'location'
:
'Twitterverse'
,
'followers_count'
:
77
,
'verified'
:
False
,
}
def
get_username
(
self
):
response_data
=
self
.
get_response_data
()
return
response_data
.
get
(
'screen_name'
)
common/djangoapps/third_party_auth/tests/testutil.py
View file @
586c2375
...
...
@@ -82,6 +82,16 @@ class ThirdPartyAuthTestMixin(object):
kwargs
.
setdefault
(
"secret"
,
"test"
)
return
cls
.
configure_oauth_provider
(
**
kwargs
)
@classmethod
def
configure_twitter_provider
(
cls
,
**
kwargs
):
""" Update the settings for the Twitter third party auth provider/backend """
kwargs
.
setdefault
(
"name"
,
"Twitter"
)
kwargs
.
setdefault
(
"backend_name"
,
"twitter"
)
kwargs
.
setdefault
(
"icon_class"
,
"fa-twitter"
)
kwargs
.
setdefault
(
"key"
,
"test"
)
kwargs
.
setdefault
(
"secret"
,
"test"
)
return
cls
.
configure_oauth_provider
(
**
kwargs
)
class
TestCase
(
ThirdPartyAuthTestMixin
,
django
.
test
.
TestCase
):
"""Base class for auth test cases."""
...
...
lms/envs/test.py
View file @
586c2375
...
...
@@ -247,6 +247,7 @@ AUTHENTICATION_BACKENDS = (
'social.backends.google.GoogleOAuth2'
,
'social.backends.linkedin.LinkedinOAuth2'
,
'social.backends.facebook.FacebookOAuth2'
,
'social.backends.twitter.TwitterOAuth'
,
'third_party_auth.dummy.DummyBackend'
,
'third_party_auth.saml.SAMLAuthBackend'
,
)
+
AUTHENTICATION_BACKENDS
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment