SSO login
and example env file
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
SPOTIFY_ENCODED_ID=<Spotify-API-Token>
|
||||||
|
OIDC_RP_CLIENT_ID=<OIDC-Client-ID>
|
||||||
|
OIDC_RP_CLIENT_SECRET=<OIDC-Client-Secret>
|
||||||
|
OIDC_OP_AUTHORIZATION_ENDPOINT=https://auth.yourwebsite.com/application/o/authorize/
|
||||||
|
OIDC_OP_TOKEN_ENDPOINT=https://auth.yourwebsite.com/application/o/token/
|
||||||
|
OIDC_OP_USER_ENDPOINT=https://auth.yourwebsite.com/application/o/userinfo/
|
||||||
@@ -1,4 +1,8 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import os
|
||||||
|
import dotenv
|
||||||
|
|
||||||
|
dotenv.load_dotenv()
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
@@ -15,6 +19,7 @@ INSTALLED_APPS = [
|
|||||||
'playlist.apps.PlaylistConfig',
|
'playlist.apps.PlaylistConfig',
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
|
'mozilla_django_oidc',
|
||||||
'django.contrib.contenttypes',
|
'django.contrib.contenttypes',
|
||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
@@ -73,6 +78,18 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
AUTHENTICATION_BACKENDS = (
|
||||||
|
'mozilla_django_oidc.auth.OIDCAuthenticationBackend',
|
||||||
|
'django.contrib.auth.backends.ModelBackend',
|
||||||
|
)
|
||||||
|
|
||||||
|
OIDC_RP_CLIENT_ID = os.getenv('OIDC_RP_CLIENT_ID')
|
||||||
|
OIDC_RP_CLIENT_SECRET = os.getenv('OIDC_RP_CLIENT_SECRET')
|
||||||
|
OIDC_OP_AUTHORIZATION_ENDPOINT = os.getenv('OIDC_OP_AUTHORIZATION_ENDPOINT')
|
||||||
|
OIDC_OP_TOKEN_ENDPOINT = os.getenv('OIDC_OP_TOKEN_ENDPOINT')
|
||||||
|
OIDC_OP_USER_ENDPOINT = os.getenv('OIDC_OP_USER_ENDPOINT')
|
||||||
|
LOGIN_REDIRECT_URL = "/"
|
||||||
|
LOGOUT_REDIRECT_URL = "/"
|
||||||
|
|
||||||
LANGUAGE_CODE = 'en-us'
|
LANGUAGE_CODE = 'en-us'
|
||||||
TIME_ZONE = 'UTC'
|
TIME_ZONE = 'UTC'
|
||||||
|
|||||||
@@ -19,5 +19,6 @@ from django.urls import path, include
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
path('oidc/', include('mozilla_django_oidc.urls')),
|
||||||
path('', include('playlist.urls')),
|
path('', include('playlist.urls')),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{% if user.is_authenticated %}
|
||||||
|
<p>Current user: {{ user.email }}</p>
|
||||||
|
<form action="{% url 'oidc_logout' %}" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<input type="submit" value="logout">
|
||||||
|
</form>
|
||||||
|
{% else %}
|
||||||
|
<a href="{% url 'oidc_authentication_init' %}">Login</a>
|
||||||
|
{% endif %}
|
||||||
+2
-1
@@ -4,5 +4,6 @@ from . import views
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('track/<str:spotify_id>', views.TrackDetailView.as_view()),
|
path('track/<str:spotify_id>', views.TrackDetailView.as_view()),
|
||||||
path('track', views.NominateView.as_view()),
|
path('track', views.NominateView.as_view()),
|
||||||
path('', views.TrackListView.as_view()),
|
#path('', views.TrackListView.as_view()),
|
||||||
|
path('', views.AuthView.as_view()),
|
||||||
]
|
]
|
||||||
|
|||||||
+4
-3
@@ -11,6 +11,10 @@ spt = spotify.Spotify()
|
|||||||
|
|
||||||
# TODO auth mixins
|
# TODO auth mixins
|
||||||
|
|
||||||
|
class AuthView(View):
|
||||||
|
def get(self, request):
|
||||||
|
return TemplateResponse(request, "Login.html", {})
|
||||||
|
|
||||||
class TrackListView(View):
|
class TrackListView(View):
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
return HttpResponse("..")
|
return HttpResponse("..")
|
||||||
@@ -40,7 +44,6 @@ class NominateView(View):
|
|||||||
# Album artists
|
# Album artists
|
||||||
album_artists = []
|
album_artists = []
|
||||||
for artist in json["album"]["artists"]:
|
for artist in json["album"]["artists"]:
|
||||||
#album_artists.append(Artist.objects.from_json(artist))
|
|
||||||
album_artists.append(from_json(Artist, artist))
|
album_artists.append(from_json(Artist, artist))
|
||||||
del json["album"]["artists"]
|
del json["album"]["artists"]
|
||||||
|
|
||||||
@@ -53,12 +56,10 @@ class NominateView(View):
|
|||||||
# Track artists
|
# Track artists
|
||||||
track_artists = []
|
track_artists = []
|
||||||
for artist in json["artists"]:
|
for artist in json["artists"]:
|
||||||
#track_artists.append(Artist.objects.from_json(artist))
|
|
||||||
track_artists.append(from_json(Artist, artist))
|
track_artists.append(from_json(Artist, artist))
|
||||||
del json["artists"]
|
del json["artists"]
|
||||||
|
|
||||||
# Track
|
# Track
|
||||||
#track = Track.objects.from_json(json)
|
|
||||||
track = from_json(Track, json)
|
track = from_json(Track, json)
|
||||||
for artist in track_artists:
|
for artist in track_artists:
|
||||||
track.artists.add(artist)
|
track.artists.add(artist)
|
||||||
|
|||||||
@@ -2,3 +2,4 @@ Django
|
|||||||
requests
|
requests
|
||||||
pillow
|
pillow
|
||||||
python-dotenv
|
python-dotenv
|
||||||
|
mozilla-django-oidc
|
||||||
|
|||||||
Reference in New Issue
Block a user