Skip to content
Snippets Groups Projects
Commit aff1a98e authored by Barnabás Czémán's avatar Barnabás Czémán
Browse files

Initial commit

parents
Branches
No related tags found
No related merge requests found
include README.rst
=====
django-authsch
=====
Django Application for AuthSCH
Quick start
-----------
1. Add "authsch" to your INSTALLED_APPS setting like this::
INSTALLED_APPS = [
...
'authsch',
]
2. settings.py
...
SOCIAL_AUTH_URL_NAMESPACE = 'social'
AUTHENTICATION_BACKENDS = [
'authsch.authentication.AuthSCHOAuth2',
'django.contrib.auth.backends.ModelBackend',
]
SOCIAL_AUTH_AUTHSCH_KEY = ...
SOCIAL_AUTH_AUTHSCH_SECRET = ...
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/'
LOGIN_URL = "login/authsch/"
...
3. Run `python manage.py migrate` to create the authsch models.
from django.conf import settings
from django.apps import AppConfig
settings.INSTALLED_APPS.append('social_django')
class AuthschConfig(AppConfig):
name = 'authsch'
from social_core.backends.oauth import BaseOAuth2
class AuthSCHOAuth2(BaseOAuth2):
"""AuthSCH OAuth2 authentication backend"""
name = 'authsch'
ID_KEY = 'internal_id'
AUTHORIZATION_URL = 'https://auth.sch.bme.hu/site/login'
ACCESS_TOKEN_URL = 'https://auth.sch.bme.hu/oauth2/token'
ACCESS_TOKEN_METHOD = 'POST'
REFRESH_TOKEN_URL = 'https://auth.sch.bme.hu/oauth2/token'
DEFAULT_SCOPE = ['basic', 'mail', 'givenName', 'sn']
EXTRA_DATA = [
('internal_id', 'id'),
('expires_in', 'expires'),
('refresh_token', 'refresh_token'),
]
def get_user_details(self, response):
"""Return user details from AuthSCH account"""
return {
'username': response.get('internal_id'),
'email': response.get('mail'),
'first_name': response.get('givenName'),
'last_name': response.get('sn')
}
def user_data(self, access_token, *args, **kwargs):
"""Loads user data from service"""
return self.get_json(
'https://auth.sch.bme.hu/api/profile/',
params={'access_token': access_token}
)
setup.py 0 → 100644
import os
from setuptools import find_packages, setup
with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as readme:
README = readme.read()
# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
setup(
name='django-authsch',
version='0.1',
packages=find_packages(),
include_package_data=True,
license='MIT License',
description='A Django app for AuthSCH.',
long_description=README,
url='https://git.sch.bme.hu/kszk/devteam/django-authsch',
author='Barnabas Czeman',
author_email='barni2000@sch.bme.hu',
install_requires=[
'social-auth-core',
'social-auth-app-django',
],
classifiers=[
'Environment :: Web Environment',
'Framework :: Django',
'Framework :: Django :: 1.11',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment