OAUTH
This commit is contained in:
parent
259fa19a87
commit
764a0c232c
@ -17,12 +17,12 @@ from django.conf.urls import url
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
from app_be.views.rest_api import TestApiClass
|
||||
from app_be.views.rest_api import *
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
url(r'^test/', TestApiClass.test_api),
|
||||
url(r'^api/login', LoginClass.login),
|
||||
]
|
||||
|
||||
router = DefaultRouter()
|
||||
|
||||
@ -3,6 +3,9 @@ import logging
|
||||
from django.http import JsonResponse
|
||||
|
||||
from rest_framework.decorators import api_view
|
||||
from oauthlib import openid
|
||||
from py_jwt_validator import PyJwtValidator, PyJwtException
|
||||
import requests
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -13,3 +16,44 @@ class TestApiClass:
|
||||
def test_api(request):
|
||||
logger.debug('Test api call: {}'.format(request))
|
||||
return JsonResponse({'Result': 'success'}, safe=False)
|
||||
|
||||
|
||||
class LoginClass:
|
||||
@staticmethod
|
||||
@api_view(['GET'])
|
||||
def login(request:requests.Request):
|
||||
logger.debug('Validating request: {}'.format(request))
|
||||
|
||||
print(request.headers)
|
||||
print(request.data)
|
||||
|
||||
bearer = request.headers['Authorization']
|
||||
jwt = bearer.split()[1]
|
||||
|
||||
print(jwt)
|
||||
|
||||
try:
|
||||
PyJwtValidator(jwt)
|
||||
except PyJwtException as e:
|
||||
print(f"Exception caught. Error: {e}")
|
||||
return JsonResponse({},status=401)
|
||||
|
||||
return JsonResponse({'Result': 'success'}, safe=False, status=200)
|
||||
|
||||
|
||||
def pretty_print_POST(req):
|
||||
"""
|
||||
At this point it is completely built and ready
|
||||
to be fired; it is "prepared".
|
||||
|
||||
However pay attention at the formatting used in
|
||||
this function because it is programmed to be pretty
|
||||
printed and may differ from the actual request.
|
||||
"""
|
||||
print('{}\n{}\r\n{}\r\n\r\n{}'.format(
|
||||
'-----------START-----------',
|
||||
req.method + ' ' + req.url,
|
||||
'\r\n'.join('{}: {}'.format(k, v) for k, v in req.headers.items()),
|
||||
req.body,
|
||||
))
|
||||
|
||||
|
||||
@ -17,6 +17,8 @@ setup(
|
||||
'channels==3.0.1',
|
||||
'channels_redis==3.2.0',
|
||||
'whitenoise==5.2.0',
|
||||
'oauth2==1.1.1',
|
||||
'oauthlib==3.1.0',
|
||||
],
|
||||
license='BSD License', # example license
|
||||
description='DESCRIPTION'
|
||||
|
||||
21959
frontend/package-lock.json
generated
21959
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -40,7 +40,7 @@ export class LoginComponent implements OnInit {
|
||||
'Accept': '*/*',
|
||||
'Access-Control-Allow-Origin': '*'
|
||||
};
|
||||
this.http.get('https://waecm-sso.inso.tuwien.ac.at/auth/realms/waecm/protocol/openid-connect/logout' +
|
||||
return this.http.get('https://waecm-sso.inso.tuwien.ac.at/auth/realms/waecm/protocol/openid-connect/logout' +
|
||||
'?id_token_hint=' + this.id_token + '&\n' +
|
||||
'post_logout_redirect_uri=https://localhost:4200/&\n' +
|
||||
'state=' + this.state,
|
||||
@ -53,9 +53,9 @@ export class LoginComponent implements OnInit {
|
||||
|
||||
gotoBackend() {
|
||||
const headerDict = {
|
||||
'Authorization': 'Bearer ' + this.id_token
|
||||
'Authorization': 'Bearer ' + this.id_token,
|
||||
};
|
||||
this.http.get('https://localhost:8000/api/login',
|
||||
return this.http.get('http://localhost:8000/api/login',
|
||||
{
|
||||
headers: new HttpHeaders(headerDict)
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user