From f31ae04982515a54fa3ce667ce7f5b6aeaf87c00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20Cz=C3=A9m=C3=A1n?= <trabarni@gmail.com> Date: Sun, 29 Oct 2017 02:36:10 +0200 Subject: [PATCH] Add authsch login --- .gitignore | 5 +++++ README.md | 10 ++++++++-- environment.bat.example | 3 +++ environment.ps1.example | 3 +++ environment.sh.example | 3 +++ requirements/base.in | 1 + requirements/development.txt | 15 ++++++++++++++- src/kszkepzes/settings.py | 16 +++++++++++++++- src/kszkepzes/urls.py | 3 ++- 9 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 environment.bat.example create mode 100644 environment.ps1.example create mode 100644 environment.sh.example diff --git a/.gitignore b/.gitignore index f4da1e7..d347aa2 100644 --- a/.gitignore +++ b/.gitignore @@ -103,3 +103,8 @@ ENV/ *.sqlite3 *.pyc + +# environment scripts +environment.sh +environment.ps1 +environment.bat diff --git a/README.md b/README.md index 8409f7d..f8cd163 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [](https://git.sch.bme.hu/kszk/devteam/kszkepzes/commits/master) ## KĂśvetelmĂŠnyek + 1. python3.5 2. pip @@ -11,11 +12,16 @@ 1. python3 -m venv venv 2. source venv/bin/activate -3. pip install -r requirements/development.txt -4. python3 src/manage.py runserver +3. mv environment.sh.example environment.sh +4. Ki kell tĂślteni a kĂśrnyezeti vĂĄltozĂłkat. +5. source environment.sh +6. pip install -r requirements/development.txt +7. python3 src/manage.py runserver ## FormĂĄlis KĂśvetelmĂŠnyek 1. flake8-nak feleljen meg 2. 125 karakternĂŠl ne legyen hosszabb sor > TODO: BĂśviteni a kĂśvetelmĂŠnyeket + +> TODO: Windows-os leĂrĂĄs diff --git a/environment.bat.example b/environment.bat.example new file mode 100644 index 0000000..7b9d14b --- /dev/null +++ b/environment.bat.example @@ -0,0 +1,3 @@ +setx SECRET_KEY <CHANGE_TO_SECRET> +setx AUTHSCH_KEY <CHANGE_TO_CLIENT_ID> +setx AUTHSCH_SECRET <CHANGE_TO_AUTHSCH_SECRET> diff --git a/environment.ps1.example b/environment.ps1.example new file mode 100644 index 0000000..9b56e25 --- /dev/null +++ b/environment.ps1.example @@ -0,0 +1,3 @@ +$env:SECRET_KEY=<CHANGE_TO_SECRET> +$env:AUTHSCH_KEY=<CHANGE_TO_CLIENT_ID> +$env:AUTHSCH_SECRET=<CHANGE_TO_AUTHSCH_SECRET> diff --git a/environment.sh.example b/environment.sh.example new file mode 100644 index 0000000..14c4e85 --- /dev/null +++ b/environment.sh.example @@ -0,0 +1,3 @@ +export SECRET_KEY=<CHANGE_TO_SECRET> +export AUTHSCH_KEY=<CHANGE_TO_CLIENT_ID> +export AUTHSCH_SECRET=<CHANGE_TO_AUTHSCH_SECRET> diff --git a/requirements/base.in b/requirements/base.in index 3e0a788..442a003 100644 --- a/requirements/base.in +++ b/requirements/base.in @@ -1,2 +1,3 @@ Django==1.11.5 djangorestframework==3.6.4 +django-social-authsch==0.1 diff --git a/requirements/development.txt b/requirements/development.txt index 0d6a745..68babd8 100644 --- a/requirements/development.txt +++ b/requirements/development.txt @@ -4,15 +4,28 @@ # # pip-compile --output-file development.txt development.in # +certifi==2017.7.27.1 # via requests +chardet==3.0.4 # via requests click==6.7 # via pip-tools +defusedxml==0.5.0 # via python3-openid, social-auth-core django-extensions==1.9.1 +django-social-authsch==0.1 django==1.11.5 djangorestframework==3.6.4 first==2.0.1 # via pip-tools flake8==3.4.1 +idna==2.6 # via requests mccabe==0.6.1 # via flake8 +oauthlib==2.0.6 # via requests-oauthlib, social-auth-core pip-tools==1.9.0 pycodestyle==2.3.1 # via flake8 pyflakes==1.5.0 # via flake8 +pyjwt==1.5.3 # via social-auth-core +python3-openid==3.1.0 # via social-auth-core pytz==2017.2 # via django -six==1.10.0 # via django-extensions, pip-tools +requests-oauthlib==0.8.0 # via social-auth-core +requests==2.18.4 # via requests-oauthlib, social-auth-core +six==1.10.0 # via django-extensions, pip-tools, social-auth-app-django, social-auth-core +social-auth-app-django==2.0.0 # via django-social-authsch +social-auth-core==1.5.0 # via django-social-authsch, social-auth-app-django +urllib3==1.22 # via requests diff --git a/src/kszkepzes/settings.py b/src/kszkepzes/settings.py index 71222b1..98e41eb 100644 --- a/src/kszkepzes/settings.py +++ b/src/kszkepzes/settings.py @@ -20,7 +20,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'zr$@t#e0f+7j%sg5o_($2=(q*$o*%-bfv(mw@o!enw5w+zt=cb' +SECRET_KEY = os.getenv('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True @@ -39,6 +39,8 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'django_extensions', 'rest_framework', + 'social_django', + 'authsch', ] MIDDLEWARE = [ @@ -101,6 +103,18 @@ AUTH_PASSWORD_VALIDATORS = [ }, ] +SOCIAL_AUTH_URL_NAMESPACE = 'social' + +AUTHENTICATION_BACKENDS = [ + 'authsch.authentication.AuthSCHOAuth2', + 'django.contrib.auth.backends.ModelBackend', +] + +SOCIAL_AUTH_AUTHSCH_KEY = os.getenv('AUTHSCH_KEY') +SOCIAL_AUTH_AUTHSCH_SECRET = os.getenv('AUTHSCH_SECRET') +SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/' +LOGIN_URL = "login/authsch/" + # Internationalization # https://docs.djangoproject.com/en/1.11/topics/i18n/ diff --git a/src/kszkepzes/urls.py b/src/kszkepzes/urls.py index 897947f..5a14337 100644 --- a/src/kszkepzes/urls.py +++ b/src/kszkepzes/urls.py @@ -13,9 +13,10 @@ Including another URLconf 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ -from django.conf.urls import url +from django.conf.urls import url, include from django.contrib import admin urlpatterns = [ url(r'^admin/', admin.site.urls), + url('', include('social_django.urls', namespace='social')), ] -- GitLab