Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

401 error on post methods #88

Open
m2jobe opened this issue Sep 15, 2017 · 0 comments
Open

401 error on post methods #88

m2jobe opened this issue Sep 15, 2017 · 0 comments
Assignees

Comments

@m2jobe
Copy link

m2jobe commented Sep 15, 2017

Launched my app today and got a 403 forbidden error on all my methods that fetch data from the DB. After some trial and error I realized that remove "credentials: include" prevent this or going into the model view and setting "authentication_classes = ()" also prevents this.

I'm curious as to why this occurred out of the blue and not yesterday whilst I was developing and the corrent method, should "credentials: include" be set and if so is it fine setting "authentication_classes = ()" or would it raise security issues?

Here is an example of one of my methods and its model view

-- METHOD

export function fetchMetrics() {

return (dispatch, state) => {

    return fetch(${SERVER_URL}/api/v1/strategy/fetchMetrics/, {
        //credentials: include,

        method: post,

        headers: {
            Accept: application/json,
            Content-Type: application/json,
            X-Requested-With: XMLHttpRequest

        }

    })
        .then(checkHttpStatus)
        .then(parseJSON)
        .then((response) => {
          dispatch(metricsDataReceived(response));
        })
        .catch((error) => {

            return Promise.resolve(); // TODO: we need a promise here because of the tests, find a better way
        });
};

}
`

-- MODEL VIEW

`

class FetchMetrics(GenericAPIView):

authentication_classes = ()
def post(self, request):
    """Process GET request and return protected data."""
    queryset = Metrics.objects.all()
    serializer = MetricsSerializer(queryset, many=True)
    data = serializer.data

    return Response(data, status=status.HTTP_200_OK)`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants