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

added token storing in $localStorage #109

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-oauth2",
"version": "4.0.0",
"version": "4.1.1",
"description": "AngularJS OAuth2",
"main": "./dist/angular-oauth2.js",
"authors": [
Expand All @@ -9,7 +9,8 @@
"keywords": [
"AngularJS",
"Authentication",
"OAuth2"
"OAuth2",
"localstorage"
],
"license": "MIT",
"homepage": "https://github.com/seegno/angular-oauth2",
Expand All @@ -25,6 +26,7 @@
"dependencies": {
"angular": "^1.4.0",
"angular-cookies": "^1.4.0",
"query-string": "^1.0.0"
"query-string": "^1.0.0",
"ngstorage": "^0.3.11"
}
}
31 changes: 17 additions & 14 deletions dist/angular-oauth2.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
/**
* angular-oauth2 - Angular OAuth2
* @version v4.1.0
* @version v4.1.1
* @link https://github.com/seegno/angular-oauth2
* @license MIT
*/
(function(root, factory) {
if (typeof define === "function" && define.amd) {
define([ "angular", "angular-cookies", "query-string" ], factory);
define([ "angular", "angular-cookies", "query-string", "ngstorage" ], factory);
} else if (typeof exports === "object") {
module.exports = factory(require("angular"), require("angular-cookies"), require("query-string"));
module.exports = factory(require("angular"), require("angular-cookies"), require("query-string"), require("ngstorage"));
} else {
root.angularOAuth2 = factory(root.angular, "ngCookies", root.queryString);
root.angularOAuth2 = factory(root.angular, "ngCookies", root.queryString, "ngStorage");
}
})(this, function(angular, ngCookies, queryString) {
var ngModule = angular.module("angular-oauth2", [ ngCookies ]).config(oauthConfig).factory("oauthInterceptor", oauthInterceptor).provider("OAuth", OAuthProvider).provider("OAuthToken", OAuthTokenProvider);
})(this, function(angular, ngCookies, queryString, ngStorage) {
var ngModule = angular.module("angular-oauth2", [ ngCookies, ngStorage ]).config(oauthConfig).factory("oauthInterceptor", oauthInterceptor).provider("OAuth", OAuthProvider).provider("OAuthToken", OAuthTokenProvider);
function oauthConfig($httpProvider) {
$httpProvider.interceptors.push("oauthInterceptor");
}
oauthConfig.$inject = [ "$httpProvider" ];
function oauthInterceptor($q, $rootScope, OAuthToken) {
return {
request: function request(config) {
Expand All @@ -36,10 +40,6 @@
};
}
oauthInterceptor.$inject = [ "$q", "$rootScope", "OAuthToken" ];
function oauthConfig($httpProvider) {
$httpProvider.interceptors.push("oauthInterceptor");
}
oauthConfig.$inject = [ "$httpProvider" ];
var _createClass = function() {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
Expand Down Expand Up @@ -221,20 +221,22 @@
angular.extend(config, params);
return config;
};
this.$get = function($cookies) {
this.$get = function($cookies, $localStorage) {
var OAuthToken = function() {
function OAuthToken() {
_classCallCheck(this, OAuthToken);
}
_createClass(OAuthToken, [ {
key: "setToken",
value: function setToken(data) {
return $cookies.putObject(config.name, data, config.options);
$cookies.putObject(config.name, data, config.options);
$localStorage[config.name] = data;
return $localStorage[config.name];
}
}, {
key: "getToken",
value: function getToken() {
return $cookies.getObject(config.name);
return $localStorage[config.name] || $cookies.getObject(config.name);
}
}, {
key: "getAccessToken",
Expand Down Expand Up @@ -262,14 +264,15 @@
}, {
key: "removeToken",
value: function removeToken() {
delete $localStorage[config.name];
return $cookies.remove(config.name, config.options);
}
} ]);
return OAuthToken;
}();
return new OAuthToken();
};
this.$get.$inject = [ "$cookies" ];
this.$get.$inject = [ "$cookies", "$localStorage" ];
}
return ngModule;
});
2 changes: 1 addition & 1 deletion dist/angular-oauth2.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ var config = {
template: `
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define([ "angular", "angular-cookies", "query-string" ], factory);
define([ "angular", "angular-cookies", "query-string", "ngstorage"], factory);
} else if (typeof exports === 'object') {
module.exports = factory(require("angular"), require("angular-cookies"), require("query-string"));
module.exports = factory(require("angular"), require("angular-cookies"), require("query-string"), require("ngstorage"));
} else {
root.<%= namespace %> = factory(root.angular, 'ngCookies', root.queryString);
root.<%= namespace %> = factory(root.angular, 'ngCookies', root.queryString,'ngStorage');
}
}(this, function(angular, ngCookies, queryString) {
}(this, function(angular, ngCookies, queryString, ngStorage) {
<% if (exports) { %>
<%= contents %>
return <%= exports %>;
Expand Down
1 change: 1 addition & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = function(config) {
files: [
'node_modules/angular/angular.js',
'node_modules/angular-cookies/angular-cookies.js',
'node_modules/ngstorage/ngStorage.js',
'node_modules/query-string/query-string.js',
'node_modules/lodash/lodash.js',
'node_modules/angular-mocks/angular-mocks.js',
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-oauth2",
"version": "4.1.0",
"version": "4.1.1",
"description": "Angular OAuth2",
"main": "./dist/angular-oauth2.js",
"repository": {
Expand All @@ -10,7 +10,8 @@
"keywords": [
"AngularJS",
"Authentication",
"OAuth2"
"OAuth2",
"localstorage"
],
"author": {
"name": "Seegno",
Expand All @@ -24,6 +25,7 @@
"dependencies": {
"angular": "^1.4.0",
"angular-cookies": "^1.4.0",
"ngstorage": "^0.3.11",
"query-string": "^1.0.0"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion src/angular-oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import OAuthTokenProvider from './providers/oauth-token-provider';
import oauthConfig from './config/oauth-config';
import oauthInterceptor from './interceptors/oauth-interceptor';
import ngCookies from 'angular-cookies';
import ngStorage from 'ngstorage';

var ngModule = angular.module('angular-oauth2', [
ngCookies
ngCookies, ngStorage
])
.config(oauthConfig)
.factory('oauthInterceptor', oauthInterceptor)
Expand Down
13 changes: 9 additions & 4 deletions src/providers/oauth-token-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,26 @@ function OAuthTokenProvider() {
* OAuthToken service.
*/

this.$get = function($cookies) {
this.$get = function($cookies,$localStorage) {
class OAuthToken {

/**
* Set token.
*/

setToken(data) {
return $cookies.putObject(config.name, data, config.options);
$cookies.putObject(config.name, data, config.options);
$localStorage[config.name]=data;
return $localStorage[config.name];
}

/**
* Get token.
*/

getToken() {
return $cookies.getObject(config.name);

return $localStorage[config.name] || $cookies.getObject(config.name);
}

/**
Expand Down Expand Up @@ -99,14 +102,16 @@ function OAuthTokenProvider() {
*/

removeToken() {

delete $localStorage[config.name];
return $cookies.remove(config.name, config.options);
}
}

return new OAuthToken();
};

this.$get.$inject = ['$cookies'];
this.$get.$inject = ['$cookies','$localStorage'];
}

/**
Expand Down
4 changes: 3 additions & 1 deletion test/mocks/angular-cookies.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ angular.module('angular-cookies.mock', [])
}
}
}
});
}).config(['$qProvider',function($qProvider){
$qProvider.errorOnUnhandledRejections(false); // done to fix rejection raised errors during tests, since angular 1.5.9
}]);