Skip to content

Commit f11cd4f

Browse files
committed
Merge pull request #25 from seegno/feature/replace-ipcookies-with-ngcookies
Replace ipCookie with ngCookies
2 parents 50e0584 + 50af200 commit f11cd4f

File tree

7 files changed

+27
-30
lines changed

7 files changed

+27
-30
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Choose your preferred method:
1717
###### 1. Download `angular-oauth2` dependencies.
1818

1919
* [angular](https://github.com/angular/angular.js)
20-
* [angular-cookie](https://github.com/ivpusic/angular-cookie)
20+
* [angular-cookies](https://github.com/angular/bower-angular-cookies)
2121
* [query-string](https://github.com/sindresorhus/query-string)
2222

2323
If you're using `bower` they will be automatically downloaded upon installing this library.
@@ -26,7 +26,7 @@ If you're using `bower` they will be automatically downloaded upon installing th
2626

2727
```html
2828
<script src="<VENDOR_FOLDER>/angular/angular.min.js"></script>
29-
<script src="<VENDOR_FOLDER>/angular-cookie/dist/angular-cookie.min.js"></script>
29+
<script src="<VENDOR_FOLDER>/angular-cookies/angular-cookies.min.js"></script>
3030
<script src="<VENDOR_FOLDER>/query-string/query-string.min.js"></script>
3131
<script src="<VENDOR_FOLDER>/angular-oauth2/dist/angular-oauth2.min.js"></script>
3232
```
@@ -146,7 +146,8 @@ OAuth.revokeToken()
146146

147147
#### OAuthTokenProvider
148148

149-
`OAuthTokenProvider` uses [angular-cookie](https://github.com/ivpusic/angular-cookie) to store the cookies. Check the [available options](https://github.com/ivpusic/angular-cookie#options).
149+
`OAuthTokenProvider` uses [angular-cookies](https://github.com/angular/bower-angular-cookies) to store the cookies. Check the [available options](https://code.angularjs.org/1.4.0/docs/api/ngCookies/service/$cookies).
150+
**BREAKING CHANGE**: `angular-oauth2` requires angular 1.4 or above in order to store cookies with additional options.
150151

151152
Configuration defaults:
152153

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
"test"
2424
],
2525
"dependencies": {
26-
"angular": "^1.3.9",
27-
"angular-cookie": "^4.0.6",
26+
"angular": "^1.4.0",
27+
"angular-cookies": "^1.4.0",
2828
"query-string": "^1.0.0"
2929
}
3030
}

karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = function(config) {
99
browsers: ['Chrome'],
1010
files: [
1111
'bower_components/angular/angular.js',
12-
'bower_components/angular-cookie/angular-cookie.js',
12+
'bower_components/angular-cookies/angular-cookies.js',
1313
'bower_components/query-string/query-string.js',
1414
'node_modules/lodash/dist/lodash.js',
1515
'node_modules/angular-mocks/angular-mocks.js',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
},
4848
"browser": {
4949
"angular": "./bower_components/angular/angular.js",
50-
"angular-cookie": "./bower_components/angular-cookie/angular-cookie.js",
50+
"angular-cookies": "./bower_components/angular-cookies/angular-cookies.js",
5151
"query-string": "./bower_components/query-string/query-string.js"
5252
},
5353
"browserify-shim": {

src/angular-oauth2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import OAuthProvider from './providers/oauth-provider';
88
import OAuthTokenProvider from './providers/oauth-token-provider';
99
import oauthConfig from './config/oauth-config';
1010
import oauthInterceptor from './interceptors/oauth-interceptor';
11-
import 'angular-cookie';
11+
import 'angular-cookies';
1212

1313
var ngModule = angular.module('angular-oauth2', [
14-
'ipCookie'
14+
'ngCookies'
1515
])
1616
.config(oauthConfig)
1717
.factory('oauthInterceptor', oauthInterceptor)

src/providers/oauth-token-provider.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@ function OAuthTokenProvider() {
4141
* @ngInject
4242
*/
4343

44-
this.$get = function(ipCookie) {
44+
this.$get = function($cookies) {
4545
class OAuthToken {
4646

4747
/**
4848
* Set token.
4949
*/
5050

5151
setToken(data) {
52-
return ipCookie(config.name, data, config.options);
52+
return $cookies.putObject(config.name, data, config.options);
5353
}
5454

5555
/**
5656
* Get token.
5757
*/
5858

5959
getToken() {
60-
return ipCookie(config.name);
60+
return $cookies.getObject(config.name);
6161
}
6262

6363
/**
@@ -101,7 +101,7 @@ function OAuthTokenProvider() {
101101
*/
102102

103103
removeToken() {
104-
return ipCookie.remove(config.name, angular.copy(config.options));
104+
return $cookies.remove(config.name, config.options);
105105
}
106106
}
107107

test/mocks/angular-cookies.mock.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,20 @@
44
*/
55

66
angular.module('angular-cookies.mock', [])
7-
.factory('ipCookie', function() {
8-
return (function () {
9-
var cookie;
7+
.provider('$cookies', function() {
8+
this.$get = function() {
9+
var cookieStore = {};
1010

11-
function cookieFun(key, value, options) {
12-
if (undefined !== value) {
13-
cookie = value;
11+
return {
12+
getObject: function(key) {
13+
return cookieStore[key];
14+
},
15+
putObject: function(key, value, options) {
16+
cookieStore[key] = value;
17+
},
18+
remove: function(key) {
19+
delete cookieStore[key];
1420
}
15-
16-
return cookie;
1721
}
18-
19-
cookieFun.remove = function(key, options) {
20-
cookie = undefined;
21-
22-
return;
23-
};
24-
25-
return cookieFun;
26-
}());
22+
}
2723
});

0 commit comments

Comments
 (0)