This repository was archived by the owner on Jun 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Texas Gateway Oauth client for academies microsite
- Loading branch information
0 parents
commit 7c4170c
Showing
13 changed files
with
431 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
*.py[cod] | ||
__pycache__ | ||
.pytest_cache/ | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Packages | ||
*.egg | ||
*.egg-info | ||
dist | ||
build | ||
eggs | ||
parts | ||
bin | ||
var | ||
sdist | ||
develop-eggs | ||
.installed.cfg | ||
lib | ||
lib64 | ||
|
||
# Installer logs | ||
pip-log.txt | ||
|
||
# Unit test / coverage reports | ||
.cache/ | ||
.coverage | ||
.coverage.* | ||
.tox | ||
coverage.xml | ||
htmlcov/ | ||
|
||
# Translations | ||
*.mo | ||
|
||
# IDEs and text editors | ||
*~ | ||
*.swp | ||
.idea/ | ||
.project | ||
.pycharm_helpers/ | ||
.pydevproject | ||
|
||
# The Silver Searcher | ||
.agignore | ||
|
||
# OS X artifacts | ||
*.DS_Store | ||
|
||
# Logging | ||
log/ | ||
logs/ | ||
chromedriver.log | ||
ghostdriver.log | ||
|
||
# Complexity | ||
output/*.html | ||
output/*/index.html | ||
|
||
# Sphinx | ||
docs/_build | ||
docs/modules.rst | ||
docs/trinity_oauth_backend.rst | ||
docs/trinity_oauth_backend.*.rst | ||
|
||
# Private requirements | ||
requirements/private.in | ||
requirements/private.txt | ||
|
||
# tox environment temporary artifacts | ||
tests/__init__.py | ||
|
||
# Development task artifacts | ||
default.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Config file for automatic testing at travis-ci.org | ||
|
||
language: python | ||
|
||
python: | ||
- 2.7 | ||
|
||
env: | ||
- PSA_BUNDLE=legacy # Ficus | ||
- PSA_BUNDLE=stable # Ginkgo | ||
- PSA_BUNDLE=latest | ||
|
||
cache: false # Ensure no leftovers from different build environments | ||
|
||
before_install: | ||
- pip install --upgrade pip | ||
|
||
install: | ||
- pip install -r requirements/test.txt | ||
- pip install -r requirements/${PSA_BUNDLE}-psa.txt | ||
|
||
script: | ||
- pycodestyle | ||
- pyflakes . | ||
- py.test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License | ||
|
||
|
||
Copyright (c) 2018 NodeRabbit Inc., d.b.a. Appsembler | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
Trinity-Academies OAuth 2 Backend | ||
============================= | ||
|
||
|travis-badge| | ||
|
||
Overview | ||
-------- | ||
|
||
A Python Social Auth backend for Texas Gateway (Trinity), mostly used for Open edX but can be used elsewhere. | ||
|
||
License | ||
------- | ||
|
||
The code in this repository is licensed under the MIT License unless | ||
otherwise noted. | ||
|
||
Please see ``LICENSE.txt`` for details. | ||
|
||
The Backend Dependency on Python Social Auth | ||
-------------------------------------------- | ||
|
||
The backend depends on Python Social Auth. It is compatible with both of the | ||
`legacy monolithic Python Social Auth | ||
<https://github.com/omab/python-social-auth>`_ | ||
that is being used on Ficus and previous releases, | ||
and the | ||
`new split Python Social Auth | ||
<https://github.com/python-social-auth/>`_ | ||
that is being used on Ginkgo and upcoming releases. | ||
|
||
SSO Endpoints | ||
------------- | ||
The backend consumes the following URLs: | ||
|
||
- **Registration:** ``https://pass.texasgateway.org/register`` | ||
- **Login:** ``https://pass.texasgateway.org/oauth/v2/auth/login`` | ||
- ``AUTHORIZATION_URL``: | ||
``https://pass.texasgateway.org/oauth/v2/auth`` | ||
- ``ACCESS_TOKEN_URL``: | ||
``https://pass.texasgateway.org/oauth/v2/token`` | ||
|
||
When using the ``staging`` environment (see below), the domain | ||
``pass-staging.texasgateway.org`` is used instead. | ||
|
||
The OAuth server provides the following information about the user: | ||
|
||
- ``email`` | ||
- ``username`` | ||
- ``fullname`` | ||
- ``district`` | ||
|
||
Backend Extra Settings | ||
---------------------- | ||
In addition to the usual client, secret key and other settings. | ||
This backend requires the ``ENVIRONMENT`` configuration: | ||
|
||
|
||
:: | ||
|
||
SOCIAL_AUTH_TRINITY_ENVIRONMENT = 'staging' # or 'production' | ||
|
||
In Open edX, this is usually set via the admin panel in the backend's **Other Settings** field: | ||
|
||
:: | ||
|
||
{ "ENVIRONMENT": "staging" } | ||
|
||
Reporting Security Issues | ||
------------------------- | ||
|
||
Please do not report security issues in public. Please email [email protected]. | ||
|
||
.. |travis-badge| image:: https://travis-ci.org/appsembler/trinity-oauth-backend.svg?branch=master | ||
:target: https://travis-ci.org/appsembler/trinity-oauth-backend | ||
:alt: Travis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
""" | ||
An OAuth backend for Texas Gateway (Trinity). | ||
It's mostly used for Open edX but can be used elsewhere. | ||
""" | ||
|
||
|
||
__version__ = '0.1.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
""" | ||
The Texas Gateway OAuth 2 backend for Academies microsite. | ||
""" | ||
|
||
try: | ||
from social.backends.oauth import BaseOAuth2 | ||
from social.exceptions import AuthException | ||
except ImportError: | ||
from social_core.backends.oauth import BaseOAuth2 | ||
from social_core.exceptions import AuthException | ||
|
||
from urllib import urlencode | ||
|
||
|
||
class AcademiesOauth2(BaseOAuth2): | ||
name = 'academies' | ||
REDIRECT_STATE = False | ||
ACCESS_TOKEN_METHOD = 'POST' | ||
SCOPE_SEPARATOR = ',' | ||
EXTRA_DATA = [ | ||
('email', 'email'), | ||
('username', 'username'), | ||
('fullname', 'fullname'), | ||
('district', 'district'), | ||
] | ||
|
||
@property | ||
def base_url(self): | ||
env = self.setting('ENVIRONMENT', default='production') | ||
|
||
if env == 'staging': | ||
return 'https://pass-staging.texasgateway.org' | ||
elif env == 'production': | ||
return 'https://pass.texasgateway.org' | ||
|
||
raise AuthException( | ||
'Invalid Trinity environment was found `{env}`, ' | ||
'valid choices are `production` and `staging`.'.format( | ||
env=env, | ||
)) | ||
|
||
def authorization_url(self): | ||
return '{base_url}/oauth/v2/auth'.format(base_url=self.base_url) | ||
|
||
def access_token_url(self): | ||
return '{base_url}/oauth/v2/token'.format(base_url=self.base_url) | ||
|
||
def get_user_details(self, response): | ||
"""Return user details from Trinity account""" | ||
fullname, _first_name, _last_name = self.get_user_names( | ||
fullname='', | ||
first_name=response.get('first_name', ''), | ||
last_name=response.get('last_name', ''), | ||
) | ||
|
||
return { | ||
'username': response.get('username'), | ||
'email': response.get('email') or '', | ||
'fullname': fullname or '', | ||
'district': response.get('original_district'), | ||
} | ||
|
||
def user_data(self, access_token, *args, **kwargs): | ||
"""Loads user data from service""" | ||
url = '{base_url}/api/v1/user/me?{params}'.format( | ||
base_url=self.base_url, | ||
params=urlencode({ | ||
'access_token': access_token, | ||
}) | ||
) | ||
|
||
return self.get_json(url) | ||
|
||
def get_user_id(self, details, response): | ||
"""Use trinity username as unique id""" | ||
return details['email'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Latest Python Social Auth | ||
social-auth-app-django | ||
social-auth-core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Legacy Python Social Auth, found in Open edX Ficus | ||
python-social-auth==0.2.21 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Stable Python Social Auth, found in Open edX Ginkgo | ||
social-auth-app-django==1.2.0 | ||
social-auth-core==1.4.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Packages for testing | ||
pytest==3.5.0 | ||
httpretty==0.8.14 | ||
unittest2==1.1.0 | ||
pycodestyle==2.4.0 | ||
pyflakes==1.6.0 | ||
-e . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[wheel] | ||
universal = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# pylint: disable=C0111,W6005,W6100 | ||
|
||
import os | ||
import re | ||
|
||
from setuptools import setup | ||
|
||
|
||
def get_version(*file_paths): | ||
""" | ||
Extract the version string from the file at the given relative path. | ||
""" | ||
filename = os.path.join(os.path.dirname(__file__), *file_paths) | ||
version_file = open(filename).read() | ||
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", | ||
version_file, re.M) | ||
if version_match: | ||
return version_match.group(1) | ||
raise RuntimeError('Unable to find version string.') | ||
|
||
|
||
VERSION = get_version('academies_oauth_backend', '__init__.py') | ||
|
||
README = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read() | ||
|
||
setup( | ||
name='academies-oauth-backend', | ||
version=VERSION, | ||
description=('An OAuth backend for Texas Gateway (Trinity), ' | ||
'mostly used for Open edX but can be used elsewhere.'), | ||
long_description=README, | ||
author='Amir Tadrisi', | ||
author_email='[email protected]', | ||
url='https://github.com/appsembler/academies-oauth-backend', | ||
packages=[ | ||
'academies_oauth_backend', | ||
], | ||
include_package_data=True, | ||
zip_safe=False, | ||
keywords='Appsembler OAuth Trinity Texas-Gateway', | ||
classifiers=[ | ||
'Intended Audience :: Developers', | ||
'License :: OSI Approved :: MIT License', | ||
], | ||
) |
Oops, something went wrong.