각도에서 내 장고 백엔드에 요청을 보내는 것은 권한이없는 401을 반환합니다. 다음은 로그 아웃 기능에 대한 http 요청입니다.Django Rest JWT로 각도 HTTP 요청
나는 컬를 통해 보낼 때 요청이 허가 그러나import { Injectable } from '@angular/core';
import { HttpClient,HttpHeaders } from '@angular/common/http';
import { RequestOptions } from '@angular/http';
import { authLoginUrl,authLogoutUrl } from '../../../../config/endpoints';
import 'rxjs/add/operator/map';
import { AlertService } from '../../../../../core/services/alert.service';
@Injectable()
export class LoginService{
public token: string;
constructor(private http: HttpClient) {
// set token if saved in local storage
var currentUser = JSON.parse(localStorage.getItem('currentUser'));
this.token = currentUser && currentUser.token;
}
logout(): void {
// notify backend of user logout
//authLogoutUrl = "http://127.0.0.1:8000/api/auth/logout/"
this.http.post(authLogoutUrl,{
headers: new HttpHeaders().set('Authorization', 'JWT ' + this.token)
})
.subscribe()
}
}
.
curl -X POST -H "Authorization: JWT <the_token>" http://localhost:8000/api/auth/logout/
로그 아웃보기 내 장고 백엔드에 : 그것은 확실히 작동하고있는 것처럼
class LogoutView(views.APIView):
permission_classes = (permissions.IsAuthenticated,)
def post(self, request, format=None):
logout(request)
return Response({}, status=status.HTTP_204_NO_CONTENT)
Everyting 보인다. 프리 플라이트 요청은 200을 반환하지만 요청 자체는 무단입니다. 여기
고르 설정이 나머지 장고 요청 헤더이다 : 그것은 컬와 공동으로 작업하여 프리 플라이트 요청이 승인되어 있기 때문에
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_HEADERS = (
'accept',
'accept-encoding',
'authorization',
'content-type',
'dnt',
'origin',
'user-agent',
'x-csrftoken',
'x-requested-with',
)
#Rest Framework
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
),
'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',),
'DEFAULT_PAGINATION_CLASS':
'rest_framework.pagination.LimitOffsetPagination',
'PAGE_SIZE':100,
}
가, 난 단지 문제가 각도 나 고르 함께 가정 할 수있다.
1) 헤더가 올바르게 설정되어 있습니까? 2) 문제가 있습니까?