[Answer]-Populate a cookie with a Django csrf token

1👍

You cannot use SessionAuthentication method if you don’t share the same domain. In your case the OAuth2Authentication is the way to go.

0👍

Assuming your angularjs code using jquery ajax to post, you can put the csrf token into the meta tag

<!--<meta name="csrf-token" content="{{csrf_token}}">-->

Then setup your jquery ajax method to include the csrf token.

jQuery(document).ajaxSend(function(event, xhr, settings) {
    if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
        //var token = $('meta[name="csrf-token"]').attr('content');
        var csrftoken = $.cookie('csrftoken');
        xhr.setRequestHeader("X-CSRFToken", csrftoken);
    }..............
});

Leave a comment