Remodelled client authorization
This commit is contained in:
parent
ca1d7fdb7a
commit
ff81894215
@ -4,12 +4,11 @@ from django.http import JsonResponse
|
||||
|
||||
from rest_framework.decorators import api_view
|
||||
from py_jwt_validator import PyJwtValidator, PyJwtException
|
||||
import requests
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def authorize(request: requests.Request):
|
||||
def authorize(request):
|
||||
logger.debug('Validating request: {}'.format(request))
|
||||
|
||||
if 'Authorization' not in request.headers:
|
||||
@ -45,7 +44,7 @@ def authorize(request: requests.Request):
|
||||
class LoginClass:
|
||||
@staticmethod
|
||||
@api_view(['GET'])
|
||||
def login(request: requests.Request):
|
||||
def login(request):
|
||||
user_sub = authorize(request)
|
||||
if not user_sub:
|
||||
return JsonResponse({}, status=401)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<app-navigation [activeLink]="'settings'"></app-navigation>
|
||||
<div class="content">
|
||||
<div class="text-center">
|
||||
<div class="container" *ngFor="let number of [1, 2, 3]">
|
||||
<div class="container" *ngFor="let number of [1]">
|
||||
<div class="row feed-list-row">
|
||||
<div class="col-2 text-center padding-0 margin-auto">
|
||||
<img class="feed-icon" src="assets/logo.svg" alt="Feed-Icon">
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import {AuthService} from '../../services/auth.service';
|
||||
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
||||
|
||||
@Component({
|
||||
selector: 'app-tweets',
|
||||
@ -7,13 +9,24 @@ import { Component, OnInit } from '@angular/core';
|
||||
})
|
||||
export class TweetsComponent implements OnInit {
|
||||
|
||||
constructor() { }
|
||||
constructor(private http: HttpClient,
|
||||
private authService: AuthService) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
loadMore() {
|
||||
console.log('TODO: Implement');
|
||||
const headerDict = {
|
||||
'Authorization': 'Bearer ' + this.authService.getToken(),
|
||||
};
|
||||
return this.http.get('http://localhost:8000/api/login',
|
||||
{
|
||||
headers: new HttpHeaders(headerDict),
|
||||
observe: 'response',
|
||||
})
|
||||
.subscribe(data => { console.log(data); alert('Returned with code: ' + data['status']); });
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user