Use withCredential with $resource
Asked Answered
L

3

8

I want to use resource with a cookie set in the navigator.

With $http it is really easy, as I only need to set withCredential to true:

$http({
    method: 'POST',
    url: url,
    data: user,
    withCredentials: true
});

But for $resource, I didn't find a solution to dot the same... I saw a discussion on github about that but I think that settings withCredential to true for all requests is not okay. Do you have an idea about how to do it?

Leibniz answered 1/9, 2013 at 19:30 Comment(0)
E
6

The config withCredentials in $resource module is available in AngularJS 1.1.2+, you can get the new version and give it a try.

Extern answered 2/9, 2013 at 1:2 Comment(0)
C
19

To change the default settings of $http (hence $resource), you need to alter $httpProvider.

Set withCredentials globally like that:

angular.module('YOUR_APP')
    .config(function($httpProvider) {
        $httpProvider.defaults.withCredentials = true;
    });
Crary answered 8/2, 2015 at 14:1 Comment(0)
E
6

The config withCredentials in $resource module is available in AngularJS 1.1.2+, you can get the new version and give it a try.

Extern answered 2/9, 2013 at 1:2 Comment(0)
D
3

You can set it the flag globally with:

 $http.defaults.withCredentials = true;

This will affect all requests from the $resource module as well as the $http module.

Duckboard answered 19/8, 2014 at 1:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.