Token validation
This commit is contained in:
parent
fed5414b5f
commit
d541b80cf2
@ -24,10 +24,11 @@ class LoginClass:
|
|||||||
def login(request:requests.Request):
|
def login(request:requests.Request):
|
||||||
logger.debug('Validating request: {}'.format(request))
|
logger.debug('Validating request: {}'.format(request))
|
||||||
|
|
||||||
print(request.headers)
|
|
||||||
print(request.data)
|
|
||||||
|
|
||||||
bearer = request.headers['Authorization']
|
bearer = request.headers['Authorization']
|
||||||
|
|
||||||
|
if len(bearer.split()) < 2:
|
||||||
|
return JsonResponse({},status=401)
|
||||||
|
|
||||||
jwt = bearer.split()[1]
|
jwt = bearer.split()[1]
|
||||||
|
|
||||||
print(jwt)
|
print(jwt)
|
||||||
@ -36,24 +37,8 @@ class LoginClass:
|
|||||||
PyJwtValidator(jwt)
|
PyJwtValidator(jwt)
|
||||||
except PyJwtException as e:
|
except PyJwtException as e:
|
||||||
print(f"Exception caught. Error: {e}")
|
print(f"Exception caught. Error: {e}")
|
||||||
|
logger.error(f"Exception caught. Error: {e}")
|
||||||
return JsonResponse({},status=401)
|
return JsonResponse({},status=401)
|
||||||
|
|
||||||
return JsonResponse({'Result': 'success'}, safe=False, status=200)
|
return JsonResponse({}, 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,
|
|
||||||
))
|
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,7 @@ setup(
|
|||||||
'whitenoise==5.2.0',
|
'whitenoise==5.2.0',
|
||||||
'oauth2==1.1.1',
|
'oauth2==1.1.1',
|
||||||
'oauthlib==3.1.0',
|
'oauthlib==3.1.0',
|
||||||
|
'py-jwt-validator==0.6.0',
|
||||||
],
|
],
|
||||||
license='BSD License', # example license
|
license='BSD License', # example license
|
||||||
description='DESCRIPTION'
|
description='DESCRIPTION'
|
||||||
|
|||||||
@ -64,8 +64,9 @@ export class LoginComponent implements OnInit {
|
|||||||
};
|
};
|
||||||
return this.http.get('http://localhost:8000/api/login',
|
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']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user