Token validation

This commit is contained in:
Manuel Hude 2021-03-20 16:22:25 +01:00
parent fed5414b5f
commit d541b80cf2
3 changed files with 10 additions and 23 deletions

View File

@ -24,10 +24,11 @@ class LoginClass:
def login(request:requests.Request):
logger.debug('Validating request: {}'.format(request))
print(request.headers)
print(request.data)
bearer = request.headers['Authorization']
if len(bearer.split()) < 2:
return JsonResponse({},status=401)
jwt = bearer.split()[1]
print(jwt)
@ -36,24 +37,8 @@ class LoginClass:
PyJwtValidator(jwt)
except PyJwtException as e:
print(f"Exception caught. Error: {e}")
logger.error(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,
))
return JsonResponse({}, safe=False, status=200)

View File

@ -19,6 +19,7 @@ setup(
'whitenoise==5.2.0',
'oauth2==1.1.1',
'oauthlib==3.1.0',
'py-jwt-validator==0.6.0',
],
license='BSD License', # example license
description='DESCRIPTION'

View File

@ -64,8 +64,9 @@ export class LoginComponent implements OnInit {
};
return this.http.get('http://localhost:8000/api/login',
{
headers: new HttpHeaders(headerDict)
headers: new HttpHeaders(headerDict),
observe: 'response',
})
.subscribe(data => console.log(data));
.subscribe(data => alert("Returned with code: "+data['status']));
}
}