@nakedcreativity/membrs-angular-helper 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/nakedcreativity-membrs-angular-helper.umd.js +247 -27
- package/bundles/nakedcreativity-membrs-angular-helper.umd.js.map +1 -1
- package/bundles/nakedcreativity-membrs-angular-helper.umd.min.js +1 -1
- package/bundles/nakedcreativity-membrs-angular-helper.umd.min.js.map +1 -1
- package/esm2015/lib/auth.interceptor.js +22 -0
- package/esm2015/lib/config.interface.js +1 -0
- package/esm2015/lib/config.service.js +7 -0
- package/esm2015/lib/membrs.module.js +107 -5
- package/esm2015/lib/membrs.service.js +87 -5
- package/esm2015/lib/router.config.js +15 -0
- package/esm2015/lib/token.js +5 -0
- package/esm2015/nakedcreativity-membrs-angular-helper.js +2 -1
- package/esm2015/public-api.js +3 -5
- package/fesm2015/nakedcreativity-membrs-angular-helper.js +225 -26
- package/fesm2015/nakedcreativity-membrs-angular-helper.js.map +1 -1
- package/lib/auth.interceptor.d.ts +6 -0
- package/lib/config.interface.d.ts +7 -0
- package/lib/config.service.d.ts +7 -0
- package/lib/membrs.module.d.ts +25 -0
- package/lib/membrs.service.d.ts +13 -1
- package/lib/router.config.d.ts +3 -0
- package/lib/token.d.ts +1 -0
- package/nakedcreativity-membrs-angular-helper.d.ts +2 -0
- package/nakedcreativity-membrs-angular-helper.metadata.json +1 -1
- package/package.json +1 -1
- package/public-api.d.ts +2 -1
- package/esm2015/lib/membrs.component.js +0 -18
- package/lib/membrs.component.d.ts +0 -5
|
@@ -1,61 +1,281 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define('@nakedcreativity/membrs-angular-helper', ['exports', '@angular/core'], factory) :
|
|
4
|
-
(global = global || self, factory((global.nakedcreativity = global.nakedcreativity || {}, global.nakedcreativity['membrs-angular-helper'] = {}), global.ng.core));
|
|
5
|
-
}(this, (function (exports, i0) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@auth0/angular-jwt'), require('@angular/common/http'), require('@angular/common'), require('@uirouter/angular'), require('rxjs/operators')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define('@nakedcreativity/membrs-angular-helper', ['exports', '@angular/core', '@auth0/angular-jwt', '@angular/common/http', '@angular/common', '@uirouter/angular', 'rxjs/operators'], factory) :
|
|
4
|
+
(global = global || self, factory((global.nakedcreativity = global.nakedcreativity || {}, global.nakedcreativity['membrs-angular-helper'] = {}), global.ng.core, global.angularJwt, global.ng.common.http, global.ng.common, global.angular, global.rxjs.operators));
|
|
5
|
+
}(this, (function (exports, i0, angularJwt, i1, common, angular, operators) { 'use strict';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* This is not a real service, but it looks like it from the outside.
|
|
9
|
+
* It's just an InjectionTToken used to import the config object, provided from the outside
|
|
10
|
+
*/
|
|
11
|
+
var MembrsConfigService = new i0.InjectionToken("MembrsConfig");
|
|
12
|
+
|
|
13
|
+
var jwtService = new angularJwt.JwtHelperService();
|
|
7
14
|
var MembrsService = /** @class */ (function () {
|
|
8
|
-
function MembrsService() {
|
|
15
|
+
function MembrsService(http, config) {
|
|
16
|
+
this.http = http;
|
|
17
|
+
this.config = config;
|
|
18
|
+
this._lsKey = 'membrs';
|
|
19
|
+
console.log('membrs constructor');
|
|
20
|
+
// if the token exists in local storage, retrieve it back to the service
|
|
21
|
+
if (localStorage.getItem(this._lsKey)) {
|
|
22
|
+
this.token = localStorage.getItem(this._lsKey);
|
|
23
|
+
}
|
|
9
24
|
}
|
|
25
|
+
MembrsService.prototype.reissue = function (token) {
|
|
26
|
+
var _this = this;
|
|
27
|
+
return new Promise(function (resolve, reject) {
|
|
28
|
+
if (!token && !_this._token) {
|
|
29
|
+
console.log('reject, not logged in');
|
|
30
|
+
reject('NOT_LOGGED_IN');
|
|
31
|
+
}
|
|
32
|
+
if (token)
|
|
33
|
+
_this.token = token;
|
|
34
|
+
// check stored token has not expired, or needs to be reissued soon
|
|
35
|
+
var reissueIn = _this._decoded.exp - Math.floor(Date.now() / 1000);
|
|
36
|
+
// token has expired
|
|
37
|
+
if (reissueIn < 0) {
|
|
38
|
+
reject('NOT_LOGGED_IN');
|
|
39
|
+
}
|
|
40
|
+
// token expiring soon
|
|
41
|
+
if (reissueIn < 300) {
|
|
42
|
+
console.log('expires less than 300');
|
|
43
|
+
console.log(_this.config);
|
|
44
|
+
_this.http.post(_this.config.apiProtocol + _this.config.api + '/token/' + _this._token, {}).subscribe(function (response) {
|
|
45
|
+
console.log('reissue response');
|
|
46
|
+
console.log(response);
|
|
47
|
+
if (response.token) {
|
|
48
|
+
_this.token = response.token;
|
|
49
|
+
resolve(_this._token);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
console.log('error');
|
|
53
|
+
console.log(response);
|
|
54
|
+
reject('NOT_LOGGED_IN');
|
|
55
|
+
}
|
|
56
|
+
}, function (error) {
|
|
57
|
+
console.log(error);
|
|
58
|
+
reject('NOT_LOGGED_IN');
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
console.log('token ok');
|
|
63
|
+
resolve(_this._token);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
Object.defineProperty(MembrsService.prototype, "token", {
|
|
68
|
+
set: function (token) {
|
|
69
|
+
this._token = token;
|
|
70
|
+
localStorage.setItem(this._lsKey, token);
|
|
71
|
+
this._decoded = jwtService.decodeToken(this._token);
|
|
72
|
+
},
|
|
73
|
+
enumerable: false,
|
|
74
|
+
configurable: true
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(MembrsService.prototype, "profile", {
|
|
77
|
+
get: function () {
|
|
78
|
+
return this._decoded;
|
|
79
|
+
},
|
|
80
|
+
enumerable: false,
|
|
81
|
+
configurable: true
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(MembrsService.prototype, "admin", {
|
|
84
|
+
get: function () {
|
|
85
|
+
return this.profile.permission == 1;
|
|
86
|
+
},
|
|
87
|
+
enumerable: false,
|
|
88
|
+
configurable: true
|
|
89
|
+
});
|
|
90
|
+
MembrsService.prototype.logout = function () {
|
|
91
|
+
var _this = this;
|
|
92
|
+
return new Promise(function (resolve, reject) {
|
|
93
|
+
_this.http.get(_this.config.apiProtocol + _this.config.api + '/token/' + _this._token + '/delete', { responseType: 'text' }).subscribe(function (response) {
|
|
94
|
+
_this._token = null;
|
|
95
|
+
localStorage.removeItem(_this._lsKey);
|
|
96
|
+
resolve(_this.config.login);
|
|
97
|
+
//this.router.stateService.go('dashboard')
|
|
98
|
+
}, function (error) {
|
|
99
|
+
reject(_this.config.login);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
};
|
|
10
103
|
return MembrsService;
|
|
11
104
|
}());
|
|
12
|
-
MembrsService.ɵprov = i0.ɵɵdefineInjectable({ factory: function MembrsService_Factory() { return new MembrsService(); }, token: MembrsService, providedIn: "root" });
|
|
105
|
+
MembrsService.ɵprov = i0.ɵɵdefineInjectable({ factory: function MembrsService_Factory() { return new MembrsService(i0.ɵɵinject(i1.HttpClient), i0.ɵɵinject(MembrsConfigService)); }, token: MembrsService, providedIn: "root" });
|
|
13
106
|
MembrsService.decorators = [
|
|
14
107
|
{ type: i0.Injectable, args: [{
|
|
15
108
|
providedIn: 'root'
|
|
16
109
|
},] }
|
|
17
110
|
];
|
|
18
|
-
MembrsService.ctorParameters = function () { return [
|
|
111
|
+
MembrsService.ctorParameters = function () { return [
|
|
112
|
+
{ type: i1.HttpClient },
|
|
113
|
+
{ type: undefined, decorators: [{ type: i0.Inject, args: [MembrsConfigService,] }] }
|
|
114
|
+
]; };
|
|
19
115
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
116
|
+
function routerConfigFn(router, injector) {
|
|
117
|
+
var transitionService = router.transitionService;
|
|
118
|
+
var stateService = router.stateService;
|
|
119
|
+
var config = injector.get(MembrsConfigService);
|
|
120
|
+
stateService.defaultErrorHandler(function (error) {
|
|
121
|
+
console.log('Default error handler - Membrs Angular Helper');
|
|
122
|
+
console.log(error);
|
|
123
|
+
if (error.detail == 'NOT_LOGGED_IN')
|
|
124
|
+
window.location.href = config.login;
|
|
125
|
+
if (error.detail == 'INSUFFICIENT_PERMISSIONS')
|
|
126
|
+
stateService.go(config.defaultState);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function retrieveToken() {
|
|
131
|
+
console.log('retrieve from ls');
|
|
132
|
+
return localStorage.getItem('membrs');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
var validateResolve = {
|
|
136
|
+
token: 'reissue',
|
|
137
|
+
deps: [angular.Transition, angular.UIRouter, MembrsService, MembrsConfigService],
|
|
138
|
+
resolveFn: validateResolveFn
|
|
139
|
+
};
|
|
140
|
+
var reissueResolve = {
|
|
141
|
+
token: 'reissue',
|
|
142
|
+
deps: [angular.Transition, angular.UIRouter, MembrsService, MembrsConfigService],
|
|
143
|
+
resolveFn: reissueResolveFn
|
|
144
|
+
};
|
|
145
|
+
var reissueState = {
|
|
146
|
+
name: 'reissue',
|
|
147
|
+
url: '/reissue?token',
|
|
148
|
+
views: {},
|
|
149
|
+
resolve: [
|
|
150
|
+
reissueResolve
|
|
151
|
+
]
|
|
152
|
+
};
|
|
153
|
+
function reissueResolveFn(transition, router, membrsService, membrsConfig) {
|
|
154
|
+
//console.log(membrsService)
|
|
155
|
+
return new Promise(function (resolve, reject) {
|
|
156
|
+
console.log('reissue promise resolve');
|
|
157
|
+
console.log(transition.params().token);
|
|
158
|
+
membrsService.reissue(transition.params().token).then(function (response) {
|
|
159
|
+
console.log('redirect to default state');
|
|
160
|
+
router.stateService.go(membrsConfig.defaultState, {}, { inherit: false });
|
|
161
|
+
reject();
|
|
162
|
+
}).catch(function (error) {
|
|
163
|
+
console.log('error in reissue resolve');
|
|
164
|
+
console.log(error);
|
|
165
|
+
//window.location.href = environment.login
|
|
166
|
+
reject(error);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function validateResolveFn(transition, router, membrsService, membrsConfig) {
|
|
171
|
+
//console.log(membrsService)
|
|
172
|
+
return new Promise(function (resolve, reject) {
|
|
173
|
+
console.log('validate promise resolve');
|
|
174
|
+
membrsService.reissue().then(function (response) {
|
|
175
|
+
resolve();
|
|
176
|
+
}).catch(function (error) {
|
|
177
|
+
console.log('error in validateResolveFn');
|
|
178
|
+
console.log(error);
|
|
179
|
+
//window.location.href = membrsConfig.login
|
|
180
|
+
//reject(error)
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
function jwtOptionsFactory(config) {
|
|
185
|
+
console.log('jwt options factory');
|
|
186
|
+
console.log(config);
|
|
187
|
+
return {
|
|
188
|
+
tokenGetter: function () {
|
|
189
|
+
console.log('token getter', localStorage.getItem('membrs'));
|
|
190
|
+
return localStorage.getItem('membrs');
|
|
191
|
+
},
|
|
192
|
+
allowedDomains: [config.api]
|
|
24
193
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
selector: 'lib-membrs',
|
|
30
|
-
template: "\n <p>\n membrs works!\n </p>\n "
|
|
31
|
-
},] }
|
|
194
|
+
}
|
|
195
|
+
/** The top level state(s) */
|
|
196
|
+
var STATES = [
|
|
197
|
+
reissueState
|
|
32
198
|
];
|
|
33
|
-
MembrsComponent.ctorParameters = function () { return []; };
|
|
34
|
-
|
|
35
199
|
var MembrsModule = /** @class */ (function () {
|
|
36
200
|
function MembrsModule() {
|
|
37
201
|
}
|
|
202
|
+
MembrsModule.forRoot = function (config) {
|
|
203
|
+
var moduleProviders = angular.UIRouterModule.forChild({
|
|
204
|
+
states: STATES,
|
|
205
|
+
config: routerConfigFn
|
|
206
|
+
}).providers;
|
|
207
|
+
moduleProviders.push(angularJwt.JwtModule.forRoot({
|
|
208
|
+
config: {
|
|
209
|
+
tokenGetter: retrieveToken,
|
|
210
|
+
allowedDomains: []
|
|
211
|
+
}
|
|
212
|
+
}).providers);
|
|
213
|
+
moduleProviders.push(MembrsService);
|
|
214
|
+
moduleProviders.push({ provide: MembrsConfigService, useValue: config });
|
|
215
|
+
return {
|
|
216
|
+
ngModule: MembrsModule,
|
|
217
|
+
providers: moduleProviders //[{provide: MembrsConfigService,useValue: config}]
|
|
218
|
+
};
|
|
219
|
+
};
|
|
38
220
|
return MembrsModule;
|
|
39
221
|
}());
|
|
40
222
|
MembrsModule.decorators = [
|
|
41
223
|
{ type: i0.NgModule, args: [{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
224
|
+
imports: [
|
|
225
|
+
common.CommonModule,
|
|
226
|
+
i1.HttpClientModule,
|
|
227
|
+
angularJwt.JwtModule
|
|
228
|
+
// JwtModule.forRoot({
|
|
229
|
+
// config: {
|
|
230
|
+
// tokenGetter: retrieveToken
|
|
231
|
+
// }
|
|
232
|
+
// })
|
|
233
|
+
// UIRouterModule.forChild({
|
|
234
|
+
// states: STATES,
|
|
235
|
+
// config: routerConfigFn,
|
|
236
|
+
// }),
|
|
237
|
+
// JwtModule.forRoot({})
|
|
238
|
+
]
|
|
45
239
|
},] }
|
|
46
240
|
];
|
|
47
241
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
242
|
+
var TokenInterceptor = /** @class */ (function () {
|
|
243
|
+
function TokenInterceptor() {
|
|
244
|
+
}
|
|
245
|
+
TokenInterceptor.prototype.intercept = function (request, next) {
|
|
246
|
+
//this.busyService.busy()
|
|
247
|
+
request = request.clone({
|
|
248
|
+
setHeaders: {
|
|
249
|
+
Authorization: localStorage.getItem('membrs')
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
return next.handle(request).pipe(operators.finalize(function () {
|
|
253
|
+
//this.busyService.finished()
|
|
254
|
+
}));
|
|
255
|
+
};
|
|
256
|
+
return TokenInterceptor;
|
|
257
|
+
}());
|
|
258
|
+
TokenInterceptor.decorators = [
|
|
259
|
+
{ type: i0.Injectable }
|
|
260
|
+
];
|
|
261
|
+
TokenInterceptor.ctorParameters = function () { return []; };
|
|
51
262
|
|
|
52
263
|
/**
|
|
53
264
|
* Generated bundle index. Do not edit.
|
|
54
265
|
*/
|
|
55
266
|
|
|
56
|
-
exports.MembrsComponent = MembrsComponent;
|
|
57
267
|
exports.MembrsModule = MembrsModule;
|
|
58
268
|
exports.MembrsService = MembrsService;
|
|
269
|
+
exports.STATES = STATES;
|
|
270
|
+
exports.TokenInterceptor = TokenInterceptor;
|
|
271
|
+
exports.jwtOptionsFactory = jwtOptionsFactory;
|
|
272
|
+
exports.reissueResolve = reissueResolve;
|
|
273
|
+
exports.reissueResolveFn = reissueResolveFn;
|
|
274
|
+
exports.reissueState = reissueState;
|
|
275
|
+
exports.retrieveToken = retrieveToken;
|
|
276
|
+
exports.validateResolve = validateResolve;
|
|
277
|
+
exports.validateResolveFn = validateResolveFn;
|
|
278
|
+
exports.ɵa = MembrsConfigService;
|
|
59
279
|
|
|
60
280
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
61
281
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nakedcreativity-membrs-angular-helper.umd.js","sources":["../../../projects/membrs/src/lib/membrs.service.ts","../../../projects/membrs/src/lib/membrs.component.ts","../../../projects/membrs/src/lib/membrs.module.ts","../../../projects/membrs/src/public-api.ts","../../../projects/membrs/src/nakedcreativity-membrs-angular-helper.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class MembrsService {\n\n constructor() { }\n}\n","import { Component, OnInit } from '@angular/core';\n\n@Component({\n selector: 'lib-membrs',\n template: `\n <p>\n membrs works!\n </p>\n `,\n styles: [\n ]\n})\nexport class MembrsComponent implements OnInit {\n\n constructor() { }\n\n ngOnInit(): void {\n }\n\n}\n","import { NgModule } from '@angular/core';\nimport { MembrsComponent } from './membrs.component';\n\n\n\n@NgModule({\n declarations: [MembrsComponent],\n imports: [\n ],\n exports: [MembrsComponent]\n})\nexport class MembrsModule { }\n","/*\n * Public API Surface of membrs\n */\n\nexport * from './lib/membrs.service';\nexport * from './lib/membrs.component';\nexport * from './lib/membrs.module';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["Injectable","Component","NgModule"],"mappings":";;;;;;;QAOE;SAAiB;;;;;gBALlBA,aAAU,SAAC;oBACV,UAAU,EAAE,MAAM;iBACnB;;;;;QCUC;SAAiB;QAEjB,kCAAQ,GAAR;SACC;;;;gBAfFC,YAAS,SAAC;oBACT,QAAQ,EAAE,YAAY;oBACtB,QAAQ,EAAE,8CAIT;iBAGF;;;;;QCAD;;;;;gBANCC,WAAQ,SAAC;oBACR,YAAY,EAAE,CAAC,eAAe,CAAC;oBAC/B,OAAO,EAAE,EACR;oBACD,OAAO,EAAE,CAAC,eAAe,CAAC;iBAC3B;;;ICVD;;;;ICAA;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"nakedcreativity-membrs-angular-helper.umd.js","sources":["../../../projects/membrs/src/lib/config.service.ts","../../../projects/membrs/src/lib/membrs.service.ts","../../../projects/membrs/src/lib/router.config.ts","../../../projects/membrs/src/lib/token.ts","../../../projects/membrs/src/lib/membrs.module.ts","../../../projects/membrs/src/lib/auth.interceptor.ts","../../../projects/membrs/src/nakedcreativity-membrs-angular-helper.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\nimport { MembrsConfig } from './config.interface';\n\n/**\n * This is not a real service, but it looks like it from the outside.\n * It's just an InjectionTToken used to import the config object, provided from the outside\n */\nexport const MembrsConfigService = new InjectionToken<MembrsConfig>(\"MembrsConfig\");\n","import { Injectable, Inject } from '@angular/core';\nimport { JwtHelperService } from '@auth0/angular-jwt';\nimport { HttpClient } from '@angular/common/http'\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\nconst jwtService = new JwtHelperService()\n\n@Injectable({\n providedIn: 'root'\n})\n\n\nexport class MembrsService {\n\n _token: string;\n _decoded: any;\n _lsKey: string = 'membrs';\n\n constructor(private http: HttpClient, @Inject(MembrsConfigService) private config: MembrsConfig) {\n\n console.log('membrs constructor')\n // if the token exists in local storage, retrieve it back to the service\n if(localStorage.getItem(this._lsKey)){\n this.token = localStorage.getItem(this._lsKey)\n }\n \n }\n\n reissue(token?:string){\n\n return new Promise((resolve, reject)=>{\n\n if(!token && !this._token){\n console.log('reject, not logged in')\n reject('NOT_LOGGED_IN')\n }\n\n if(token)\n this.token = token\n\n // check stored token has not expired, or needs to be reissued soon\n var reissueIn = this._decoded.exp - Math.floor(Date.now()/1000)\n \n // token has expired\n if(reissueIn < 0){\n reject('NOT_LOGGED_IN')\n }\n \n // token expiring soon\n if(reissueIn < 300){\n \n console.log('expires less than 300')\n \n \n console.log(this.config)\n\n this.http.post(this.config.apiProtocol + this.config.api+'/token/'+this._token, {}).subscribe((response:any)=>{\n console.log('reissue response')\n console.log(response)\n if(response.token){\n this.token = response.token\n resolve(this._token)\n }else {\n console.log('error')\n console.log(response)\n reject('NOT_LOGGED_IN')\n }\n \n }, error=>{\n console.log(error)\n reject('NOT_LOGGED_IN')\n })\n\n }else {\n console.log('token ok')\n resolve(this._token)\n }\n \n })\n \n }\n\n set token(token){\n this._token = token\n localStorage.setItem(this._lsKey, token)\n this._decoded = jwtService.decodeToken(this._token)\n }\n\n get profile(){\n return this._decoded\n }\n\n get admin (){\n return this.profile.permission == 1\n }\n\n logout(){\n return new Promise((resolve, reject)=>{\n this.http.get(this.config.apiProtocol+this.config.api+'/token/'+this._token+'/delete', {responseType: 'text'}).subscribe((response:any)=>{\n this._token = null;\n localStorage.removeItem(this._lsKey)\n resolve(this.config.login)\n //this.router.stateService.go('dashboard')\n }, error=>{\n reject(this.config.login)\n })\n })\n \n }\n\n\n}\n","import { UIRouter } from '@uirouter/core';\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\nimport { Injector } from '@angular/core';\n\nexport function routerConfigFn(router: UIRouter, injector: Injector) {\n\n const transitionService = router.transitionService;\n const stateService = router.stateService\n const config:MembrsConfig = injector.get(MembrsConfigService)\n\n \tstateService.defaultErrorHandler(function(error) {\n\t\t \n\t\tconsole.log('Default error handler - Membrs Angular Helper')\n\t\tconsole.log(error)\n\t\t\t\n\t\tif(error.detail == 'NOT_LOGGED_IN')\n\t\t\twindow.location.href = config.login;\n\n\t\tif(error.detail == 'INSUFFICIENT_PERMISSIONS')\n\t\t\tstateService.go(config.defaultState)\n\n\t});\n\t\n}","export function retrieveToken() {\n console.log('retrieve from ls')\n return localStorage.getItem('membrs');\n}","import { NgModule, ModuleWithProviders, Injector } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { MembrsService } from './membrs.service';\nimport { JwtModule, JWT_OPTIONS } from \"@auth0/angular-jwt\";\nimport { HttpClientModule } from \"@angular/common/http\";\nimport { UIRouterModule } from '@uirouter/angular'\n\nimport { Ng2StateDeclaration } from '@uirouter/angular';\nimport { Transition, UIRouter } from '@uirouter/angular'\n\nimport { routerConfigFn } from './router.config';\nimport { MembrsConfig } from './config.interface';\nimport { MembrsConfigService } from './config.service';\nimport { retrieveToken } from './token';\n\nexport const validateResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService, MembrsConfigService ],\n resolveFn: validateResolveFn\n}\n\nexport const reissueResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService, MembrsConfigService ],\n resolveFn: reissueResolveFn\n}\n\nexport const reissueState:Ng2StateDeclaration = {\n\tname: 'reissue', \n\turl: '/reissue?token',\n\tviews: { },\n\tresolve: [\n reissueResolve\n\t]\n}\n\nexport function reissueResolveFn(transition, router, membrsService, membrsConfig:MembrsConfig) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('reissue promise resolve')\n console.log(transition.params().token)\n membrsService.reissue(transition.params().token).then((response)=>{\n console.log('redirect to default state')\n router.stateService.go(membrsConfig.defaultState, {}, {inherit:false})\n reject()\n }).catch(error=>{\n console.log('error in reissue resolve')\n console.log(error)\n //window.location.href = environment.login\n reject(error)\n })\n\n\t})\n}\n\nexport function validateResolveFn(transition, router, membrsService, membrsConfig:MembrsConfig) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('validate promise resolve')\n \n membrsService.reissue().then((response)=>{\n resolve()\n }).catch(error=>{\n console.log('error in validateResolveFn')\n console.log(error)\n //window.location.href = membrsConfig.login\n //reject(error)\n })\n\n})\n}\n\nexport function jwtOptionsFactory(config) {\n console.log('jwt options factory')\n console.log(config)\n return {\n tokenGetter: () => {\n console.log('token getter', localStorage.getItem('membrs'))\n return localStorage.getItem('membrs');\n },\n allowedDomains: [config.api]\n }\n}\n\n\n/** The top level state(s) */\nexport const STATES = [\n reissueState\n]\n\n\n@NgModule({\n imports: [\n CommonModule,\n HttpClientModule,\n JwtModule\n // JwtModule.forRoot({\n // config: {\n // tokenGetter: retrieveToken\n // }\n // })\n // UIRouterModule.forChild({\n // states: STATES,\n // config: routerConfigFn,\n // }),\n // JwtModule.forRoot({})\n ]\n})\n\n\n\nexport class MembrsModule { \n static forRoot(config: MembrsConfig): ModuleWithProviders<MembrsModule> {\n\n\n const moduleProviders = UIRouterModule.forChild({\n states: STATES,\n config: routerConfigFn\n }).providers\n\n moduleProviders.push(JwtModule.forRoot({\n config: {\n tokenGetter: retrieveToken,\n allowedDomains: []\n }\n }).providers)\n \n moduleProviders.push(MembrsService)\n moduleProviders.push({provide: MembrsConfigService,useValue: config});\n \n \n return {\n ngModule: MembrsModule, \n providers: moduleProviders //[{provide: MembrsConfigService,useValue: config}]\n };\n \n }\n\n}\n","import { Injectable } from '@angular/core';\nimport {\n HttpRequest,\n HttpHandler,\n HttpEvent,\n HttpInterceptor\n} from '@angular/common/http';\nimport { Observable } from 'rxjs';\n//import { NgBusyService } from '@nakedcreativity/ng-busy';\nimport { finalize } from 'rxjs/operators';\n\n\n@Injectable()\nexport class TokenInterceptor implements HttpInterceptor {\n constructor() {}\n intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n \n //this.busyService.busy()\n request = request.clone({\n setHeaders: {\n Authorization: localStorage.getItem('membrs')\n }\n });\n return next.handle(request).pipe(finalize(()=>{\n //this.busyService.finished()\n }));\n }\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n\nexport {MembrsConfig as ɵb} from './lib/config.interface';\nexport {MembrsConfigService as ɵa} from './lib/config.service';"],"names":["InjectionToken","JwtHelperService","Injectable","HttpClient","Inject","Transition","UIRouter","UIRouterModule","JwtModule","NgModule","CommonModule","HttpClientModule","finalize"],"mappings":";;;;;;IAGA;;;;QAIa,mBAAmB,GAAG,IAAIA,iBAAc,CAAe,cAAc;;ICFlF,IAAM,UAAU,GAAG,IAAIC,2BAAgB,EAAE,CAAA;;QAavC,uBAAoB,IAAgB,EAAuC,MAAoB;YAA3E,SAAI,GAAJ,IAAI,CAAY;YAAuC,WAAM,GAAN,MAAM,CAAc;YAF/F,WAAM,GAAW,QAAQ,CAAC;YAIxB,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;;YAEjC,IAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAC;gBACnC,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;aAC/C;SAEF;QAED,+BAAO,GAAP,UAAQ,KAAa;YAArB,iBAoDC;YAlDC,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;gBAEjC,IAAG,CAAC,KAAK,IAAI,CAAC,KAAI,CAAC,MAAM,EAAC;oBACxB,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAA;oBACpC,MAAM,CAAC,eAAe,CAAC,CAAA;iBACxB;gBAED,IAAG,KAAK;oBACN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AC,CAAC;YACH,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAACI,kBAAQ,CAAC;;aAEzC,CAAC,CAAC,CAAC;SACL;;;;gBAdFV,aAAU;;;;ICZX;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,
|
|
1
|
+
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@angular/core"),require("@auth0/angular-jwt"),require("@angular/common/http"),require("@angular/common"),require("@uirouter/angular"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@nakedcreativity/membrs-angular-helper",["exports","@angular/core","@auth0/angular-jwt","@angular/common/http","@angular/common","@uirouter/angular","rxjs/operators"],o):o(((e=e||self).nakedcreativity=e.nakedcreativity||{},e.nakedcreativity["membrs-angular-helper"]={}),e.ng.core,e.angularJwt,e.ng.common.http,e.ng.common,e.angular,e.rxjs.operators)}(this,(function(e,o,t,n,r,i,s){"use strict";var l=new o.InjectionToken("MembrsConfig"),a=new t.JwtHelperService,c=function(){function e(e,o){this.http=e,this.config=o,this._lsKey="membrs",console.log("membrs constructor"),localStorage.getItem(this._lsKey)&&(this.token=localStorage.getItem(this._lsKey))}return e.prototype.reissue=function(e){var o=this;return new Promise((function(t,n){e||o._token||(console.log("reject, not logged in"),n("NOT_LOGGED_IN")),e&&(o.token=e);var r=o._decoded.exp-Math.floor(Date.now()/1e3);r<0&&n("NOT_LOGGED_IN"),r<300?(console.log("expires less than 300"),console.log(o.config),o.http.post(o.config.apiProtocol+o.config.api+"/token/"+o._token,{}).subscribe((function(e){console.log("reissue response"),console.log(e),e.token?(o.token=e.token,t(o._token)):(console.log("error"),console.log(e),n("NOT_LOGGED_IN"))}),(function(e){console.log(e),n("NOT_LOGGED_IN")}))):(console.log("token ok"),t(o._token))}))},Object.defineProperty(e.prototype,"token",{set:function(e){this._token=e,localStorage.setItem(this._lsKey,e),this._decoded=a.decodeToken(this._token)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"profile",{get:function(){return this._decoded},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"admin",{get:function(){return 1==this.profile.permission},enumerable:!1,configurable:!0}),e.prototype.logout=function(){var e=this;return new Promise((function(o,t){e.http.get(e.config.apiProtocol+e.config.api+"/token/"+e._token+"/delete",{responseType:"text"}).subscribe((function(t){e._token=null,localStorage.removeItem(e._lsKey),o(e.config.login)}),(function(o){t(e.config.login)}))}))},e}();function u(e,o){e.transitionService;var t=e.stateService,n=o.get(l);t.defaultErrorHandler((function(e){console.log("Default error handler - Membrs Angular Helper"),console.log(e),"NOT_LOGGED_IN"==e.detail&&(window.location.href=n.login),"INSUFFICIENT_PERMISSIONS"==e.detail&&t.go(n.defaultState)}))}function g(){return console.log("retrieve from ls"),localStorage.getItem("membrs")}c.ɵprov=o.ɵɵdefineInjectable({factory:function(){return new c(o.ɵɵinject(n.HttpClient),o.ɵɵinject(l))},token:c,providedIn:"root"}),c.decorators=[{type:o.Injectable,args:[{providedIn:"root"}]}],c.ctorParameters=function(){return[{type:n.HttpClient},{type:void 0,decorators:[{type:o.Inject,args:[l]}]}]};var f={token:"reissue",deps:[i.Transition,i.UIRouter,c,l],resolveFn:v},p={token:"reissue",deps:[i.Transition,i.UIRouter,c,l],resolveFn:m},d={name:"reissue",url:"/reissue?token",views:{},resolve:[p]};function m(e,o,t,n){return new Promise((function(r,i){console.log("reissue promise resolve"),console.log(e.params().token),t.reissue(e.params().token).then((function(e){console.log("redirect to default state"),o.stateService.go(n.defaultState,{},{inherit:!1}),i()})).catch((function(e){console.log("error in reissue resolve"),console.log(e),i(e)}))}))}function v(e,o,t,n){return new Promise((function(e,o){console.log("validate promise resolve"),t.reissue().then((function(o){e()})).catch((function(e){console.log("error in validateResolveFn"),console.log(e)}))}))}var h=[d],k=function(){function e(){}return e.forRoot=function(o){var n=i.UIRouterModule.forChild({states:h,config:u}).providers;return n.push(t.JwtModule.forRoot({config:{tokenGetter:g,allowedDomains:[]}}).providers),n.push(c),n.push({provide:l,useValue:o}),{ngModule:e,providers:n}},e}();k.decorators=[{type:o.NgModule,args:[{imports:[r.CommonModule,n.HttpClientModule,t.JwtModule]}]}];var y=function(){function e(){}return e.prototype.intercept=function(e,o){return e=e.clone({setHeaders:{Authorization:localStorage.getItem("membrs")}}),o.handle(e).pipe(s.finalize((function(){})))},e}();y.decorators=[{type:o.Injectable}],y.ctorParameters=function(){return[]},e.MembrsModule=k,e.MembrsService=c,e.STATES=h,e.TokenInterceptor=y,e.jwtOptionsFactory=function(e){return console.log("jwt options factory"),console.log(e),{tokenGetter:function(){return console.log("token getter",localStorage.getItem("membrs")),localStorage.getItem("membrs")},allowedDomains:[e.api]}},e.reissueResolve=p,e.reissueResolveFn=m,e.reissueState=d,e.retrieveToken=g,e.validateResolve=f,e.validateResolveFn=v,e.ɵa=l,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=nakedcreativity-membrs-angular-helper.umd.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../projects/membrs/src/lib/membrs.service.ts","../../../projects/membrs/src/lib/membrs.component.ts","../../../projects/membrs/src/lib/membrs.module.ts"],"names":["Injectable","args","providedIn","MembrsComponent","prototype","ngOnInit","Component","selector","template","NgModule","declarations","imports","exports"],"mappings":"oXAOE,4HALDA,EAAAA,WAAUC,KAAA,CAAC,CACVC,WAAY,kECWZ,SAAAC,YAEAA,EAAAC,UAAAC,SAAA,sCAdDC,EAAAA,UAASL,KAAA,CAAC,CACTM,SAAU,aACVC,SAAU,+FCOZ,iCANCC,EAAAA,SAAQR,KAAA,CAAC,CACRS,aAAc,CAACP,GACfQ,QAAS,GAETC,QAAS,CAACT","sourcesContent":["import { Injectable } from '@angular/core';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class MembrsService {\n\n constructor() { }\n}\n","import { Component, OnInit } from '@angular/core';\n\n@Component({\n selector: 'lib-membrs',\n template: `\n <p>\n membrs works!\n </p>\n `,\n styles: [\n ]\n})\nexport class MembrsComponent implements OnInit {\n\n constructor() { }\n\n ngOnInit(): void {\n }\n\n}\n","import { NgModule } from '@angular/core';\nimport { MembrsComponent } from './membrs.component';\n\n\n\n@NgModule({\n declarations: [MembrsComponent],\n imports: [\n ],\n exports: [MembrsComponent]\n})\nexport class MembrsModule { }\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../projects/membrs/src/lib/config.service.ts","../../../projects/membrs/src/lib/membrs.service.ts","../../../projects/membrs/src/lib/router.config.ts","../../../projects/membrs/src/lib/token.ts","../../../projects/membrs/src/lib/membrs.module.ts","../../../projects/membrs/src/lib/auth.interceptor.ts"],"names":["MembrsConfigService","InjectionToken","jwtService","JwtHelperService","MembrsService","http","config","this","_lsKey","console","log","localStorage","getItem","token","prototype","reissue","_this","Promise","resolve","reject","_token","reissueIn","_decoded","exp","Math","floor","Date","now","post","apiProtocol","api","subscribe","response","error","Object","defineProperty","setItem","decodeToken","profile","permission","logout","get","responseType","removeItem","login","routerConfigFn","router","injector","transitionService","stateService","defaultErrorHandler","detail","window","location","href","go","defaultState","retrieveToken","Injectable","args","providedIn","HttpClient","Inject","validateResolve","deps","Transition","UIRouter","resolveFn","validateResolveFn","reissueResolve","reissueResolveFn","reissueState","name","url","views","transition","membrsService","membrsConfig","params","then","inherit","catch","STATES","MembrsModule","forRoot","moduleProviders","UIRouterModule","forChild","states","providers","push","JwtModule","tokenGetter","allowedDomains","provide","useValue","ngModule","NgModule","imports","CommonModule","HttpClientModule","TokenInterceptor","intercept","request","next","clone","setHeaders","Authorization","handle","pipe","finalize"],"mappings":"orBAOaA,EAAsB,IAAIC,EAAAA,eAA6B,gBCF9DC,EAAa,IAAIC,EAAAA,8BAarB,SAAAC,EAAoBC,EAAuDC,GAAvDC,KAAAF,KAAAA,EAAuDE,KAAAD,OAAAA,EAF3EC,KAAAC,OAAiB,SAIfC,QAAQC,IAAI,sBAETC,aAAaC,QAAQL,KAAKC,UA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AC/D7D,OACD8D,OAAM,SAAAhD,GACLxB,QAAQC,IAAI,4BACZD,QAAQC,IAAIuB,GAEZd,EAAOc,kBAMDmC,EAAkBO,EAAY7B,EAAQ8B,EAAeC,GAGnE,OAAO,IAAI5D,SAAQ,SAACC,EAASC,GAC3BV,QAAQC,IAAI,4BAEZkE,EAAc7D,UAAUgE,MAAK,SAAC/C,GAC1Bd,OACD+D,OAAM,SAAAhD,GACPxB,QAAQC,IAAI,8BACZD,QAAQC,IAAIuB,aAsBLiD,EAAS,CAClBX,gBAwBJ,SAAAY,YACSA,EAAAC,QAAP,SAAe9E,GAGb,IAAM+E,EAAkBC,EAAAA,eAAeC,SAAS,CAC9CC,OAAQN,EACR5E,OAAQuC,IACP4C,UAaH,OAXAJ,EAAgBK,KAAKC,EAAAA,UAAUP,QAAQ,CACrC9E,OAAQ,CACNsF,YAAanC,EACboC,eAAgB,MAEjBJ,WAEHJ,EAAgBK,KAAKtF,GACrBiF,EAAgBK,KAAK,CAACI,QAAS9F,EAAoB+F,SAAUzF,IAGtD,CACL0F,SAAUb,EACVM,UAAWJ,6BA1ChBY,EAAAA,SAAQtC,KAAA,CAAC,CACRuC,QAAS,CACPC,EAAAA,aACAC,EAAAA,iBACAT,EAAAA,gCCnFF,SAAAU,YACAA,EAAAvF,UAAAwF,UAAA,SAAUC,EAA2BC,GAQnC,OALAD,EAAUA,EAAQE,MAAM,CACtBC,WAAY,CACVC,cAAehG,aAAaC,QAAQ,aAGjC4F,EAAKI,OAAOL,GAASM,KAAKC,EAAAA,UAAS,0CAX7CpD,EAAAA,mJD8DiCpD,GAGhC,OAFAG,QAAQC,IAAI,uBACZD,QAAQC,IAAIJ,GACL,CACLsF,YAAa,WAEX,OADAnF,QAAQC,IAAI,eAAiBC,aAAaC,QAAQ,WAC3CD,aAAaC,QAAQ,WAE9BiF,eAAgB,CAACvF,EAAOwB","sourcesContent":["import { InjectionToken } from '@angular/core';\nimport { MembrsConfig } from './config.interface';\n\n/**\n * This is not a real service, but it looks like it from the outside.\n * It's just an InjectionTToken used to import the config object, provided from the outside\n */\nexport const MembrsConfigService = new InjectionToken<MembrsConfig>(\"MembrsConfig\");\n","import { Injectable, Inject } from '@angular/core';\nimport { JwtHelperService } from '@auth0/angular-jwt';\nimport { HttpClient } from '@angular/common/http'\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\nconst jwtService = new JwtHelperService()\n\n@Injectable({\n providedIn: 'root'\n})\n\n\nexport class MembrsService {\n\n _token: string;\n _decoded: any;\n _lsKey: string = 'membrs';\n\n constructor(private http: HttpClient, @Inject(MembrsConfigService) private config: MembrsConfig) {\n\n console.log('membrs constructor')\n // if the token exists in local storage, retrieve it back to the service\n if(localStorage.getItem(this._lsKey)){\n this.token = localStorage.getItem(this._lsKey)\n }\n \n }\n\n reissue(token?:string){\n\n return new Promise((resolve, reject)=>{\n\n if(!token && !this._token){\n console.log('reject, not logged in')\n reject('NOT_LOGGED_IN')\n }\n\n if(token)\n this.token = token\n\n // check stored token has not expired, or needs to be reissued soon\n var reissueIn = this._decoded.exp - Math.floor(Date.now()/1000)\n \n // token has expired\n if(reissueIn < 0){\n reject('NOT_LOGGED_IN')\n }\n \n // token expiring soon\n if(reissueIn < 300){\n \n console.log('expires less than 300')\n \n \n console.log(this.config)\n\n this.http.post(this.config.apiProtocol + this.config.api+'/token/'+this._token, {}).subscribe((response:any)=>{\n console.log('reissue response')\n console.log(response)\n if(response.token){\n this.token = response.token\n resolve(this._token)\n }else {\n console.log('error')\n console.log(response)\n reject('NOT_LOGGED_IN')\n }\n \n }, error=>{\n console.log(error)\n reject('NOT_LOGGED_IN')\n })\n\n }else {\n console.log('token ok')\n resolve(this._token)\n }\n \n })\n \n }\n\n set token(token){\n this._token = token\n localStorage.setItem(this._lsKey, token)\n this._decoded = jwtService.decodeToken(this._token)\n }\n\n get profile(){\n return this._decoded\n }\n\n get admin (){\n return this.profile.permission == 1\n }\n\n logout(){\n return new Promise((resolve, reject)=>{\n this.http.get(this.config.apiProtocol+this.config.api+'/token/'+this._token+'/delete', {responseType: 'text'}).subscribe((response:any)=>{\n this._token = null;\n localStorage.removeItem(this._lsKey)\n resolve(this.config.login)\n //this.router.stateService.go('dashboard')\n }, error=>{\n reject(this.config.login)\n })\n })\n \n }\n\n\n}\n","import { UIRouter } from '@uirouter/core';\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\nimport { Injector } from '@angular/core';\n\nexport function routerConfigFn(router: UIRouter, injector: Injector) {\n\n const transitionService = router.transitionService;\n const stateService = router.stateService\n const config:MembrsConfig = injector.get(MembrsConfigService)\n\n \tstateService.defaultErrorHandler(function(error) {\n\t\t \n\t\tconsole.log('Default error handler - Membrs Angular Helper')\n\t\tconsole.log(error)\n\t\t\t\n\t\tif(error.detail == 'NOT_LOGGED_IN')\n\t\t\twindow.location.href = config.login;\n\n\t\tif(error.detail == 'INSUFFICIENT_PERMISSIONS')\n\t\t\tstateService.go(config.defaultState)\n\n\t});\n\t\n}","export function retrieveToken() {\n console.log('retrieve from ls')\n return localStorage.getItem('membrs');\n}","import { NgModule, ModuleWithProviders, Injector } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { MembrsService } from './membrs.service';\nimport { JwtModule, JWT_OPTIONS } from \"@auth0/angular-jwt\";\nimport { HttpClientModule } from \"@angular/common/http\";\nimport { UIRouterModule } from '@uirouter/angular'\n\nimport { Ng2StateDeclaration } from '@uirouter/angular';\nimport { Transition, UIRouter } from '@uirouter/angular'\n\nimport { routerConfigFn } from './router.config';\nimport { MembrsConfig } from './config.interface';\nimport { MembrsConfigService } from './config.service';\nimport { retrieveToken } from './token';\n\nexport const validateResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService, MembrsConfigService ],\n resolveFn: validateResolveFn\n}\n\nexport const reissueResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService, MembrsConfigService ],\n resolveFn: reissueResolveFn\n}\n\nexport const reissueState:Ng2StateDeclaration = {\n\tname: 'reissue', \n\turl: '/reissue?token',\n\tviews: { },\n\tresolve: [\n reissueResolve\n\t]\n}\n\nexport function reissueResolveFn(transition, router, membrsService, membrsConfig:MembrsConfig) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('reissue promise resolve')\n console.log(transition.params().token)\n membrsService.reissue(transition.params().token).then((response)=>{\n console.log('redirect to default state')\n router.stateService.go(membrsConfig.defaultState, {}, {inherit:false})\n reject()\n }).catch(error=>{\n console.log('error in reissue resolve')\n console.log(error)\n //window.location.href = environment.login\n reject(error)\n })\n\n\t})\n}\n\nexport function validateResolveFn(transition, router, membrsService, membrsConfig:MembrsConfig) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('validate promise resolve')\n \n membrsService.reissue().then((response)=>{\n resolve()\n }).catch(error=>{\n console.log('error in validateResolveFn')\n console.log(error)\n //window.location.href = membrsConfig.login\n //reject(error)\n })\n\n})\n}\n\nexport function jwtOptionsFactory(config) {\n console.log('jwt options factory')\n console.log(config)\n return {\n tokenGetter: () => {\n console.log('token getter', localStorage.getItem('membrs'))\n return localStorage.getItem('membrs');\n },\n allowedDomains: [config.api]\n }\n}\n\n\n/** The top level state(s) */\nexport const STATES = [\n reissueState\n]\n\n\n@NgModule({\n imports: [\n CommonModule,\n HttpClientModule,\n JwtModule\n // JwtModule.forRoot({\n // config: {\n // tokenGetter: retrieveToken\n // }\n // })\n // UIRouterModule.forChild({\n // states: STATES,\n // config: routerConfigFn,\n // }),\n // JwtModule.forRoot({})\n ]\n})\n\n\n\nexport class MembrsModule { \n static forRoot(config: MembrsConfig): ModuleWithProviders<MembrsModule> {\n\n\n const moduleProviders = UIRouterModule.forChild({\n states: STATES,\n config: routerConfigFn\n }).providers\n\n moduleProviders.push(JwtModule.forRoot({\n config: {\n tokenGetter: retrieveToken,\n allowedDomains: []\n }\n }).providers)\n \n moduleProviders.push(MembrsService)\n moduleProviders.push({provide: MembrsConfigService,useValue: config});\n \n \n return {\n ngModule: MembrsModule, \n providers: moduleProviders //[{provide: MembrsConfigService,useValue: config}]\n };\n \n }\n\n}\n","import { Injectable } from '@angular/core';\nimport {\n HttpRequest,\n HttpHandler,\n HttpEvent,\n HttpInterceptor\n} from '@angular/common/http';\nimport { Observable } from 'rxjs';\n//import { NgBusyService } from '@nakedcreativity/ng-busy';\nimport { finalize } from 'rxjs/operators';\n\n\n@Injectable()\nexport class TokenInterceptor implements HttpInterceptor {\n constructor() {}\n intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n \n //this.busyService.busy()\n request = request.clone({\n setHeaders: {\n Authorization: localStorage.getItem('membrs')\n }\n });\n return next.handle(request).pipe(finalize(()=>{\n //this.busyService.finished()\n }));\n }\n}"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
//import { NgBusyService } from '@nakedcreativity/ng-busy';
|
|
3
|
+
import { finalize } from 'rxjs/operators';
|
|
4
|
+
export class TokenInterceptor {
|
|
5
|
+
constructor() { }
|
|
6
|
+
intercept(request, next) {
|
|
7
|
+
//this.busyService.busy()
|
|
8
|
+
request = request.clone({
|
|
9
|
+
setHeaders: {
|
|
10
|
+
Authorization: localStorage.getItem('membrs')
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
return next.handle(request).pipe(finalize(() => {
|
|
14
|
+
//this.busyService.finished()
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
TokenInterceptor.decorators = [
|
|
19
|
+
{ type: Injectable }
|
|
20
|
+
];
|
|
21
|
+
TokenInterceptor.ctorParameters = () => [];
|
|
22
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXV0aC5pbnRlcmNlcHRvci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3Byb2plY3RzL21lbWJycy9zcmMvbGliL2F1dGguaW50Z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XG59Il19
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
/**
|
|
3
|
+
* This is not a real service, but it looks like it from the outside.
|
|
4
|
+
* It's just an InjectionTToken used to import the config object, provided from the outside
|
|
5
|
+
*/
|
|
6
|
+
export const MembrsConfigService = new InjectionToken("MembrsConfig");
|
|
7
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlnLnNlcnZpY2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9wcm9qZWN0cy9tZW1icnMvc3JjL2xpYi9jb25maWcuc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsY0FBYyxFQUFFLE1BQU0sZUFBZSxDQUFDO0FBRy9DOzs7R0FHRztBQUNILE1BQU0sQ0FBQyxNQUFNLG1CQUFtQixHQUFHLElBQUksY0FBYyxDQUFlLGNBQWMsQ0FBQyxDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgSW5qZWN0aW9uVG9rZW4gfSBmcm9tICdAYW5ndWxhci9jb3JlJztcbmltcG9ydCB7IE1lbWJyc0NvbmZpZyB9IGZyb20gJy4vY29uZmlnLmludGVyZmFjZSc7XG5cbi8qKlxuICogVGhpcyBpcyBub3QgYSByZWFsIHNlcnZpY2UsIGJ1dCBpdCBsb29rcyBsaWtlIGl0IGZyb20gdGhlIG91dHNpZGUuXG4gKiBJdCdzIGp1c3QgYW4gSW5qZWN0aW9uVFRva2VuIHVzZWQgdG8gaW1wb3J0IHRoZSBjb25maWcgb2JqZWN0LCBwcm92aWRlZCBmcm9tIHRoZSBvdXRzaWRlXG4gKi9cbmV4cG9ydCBjb25zdCBNZW1icnNDb25maWdTZXJ2aWNlID0gbmV3IEluamVjdGlvblRva2VuPE1lbWJyc0NvbmZpZz4oXCJNZW1icnNDb25maWdcIik7XG4iXX0=
|
|
@@ -1,12 +1,114 @@
|
|
|
1
1
|
import { NgModule } from '@angular/core';
|
|
2
|
-
import {
|
|
2
|
+
import { CommonModule } from '@angular/common';
|
|
3
|
+
import { MembrsService } from './membrs.service';
|
|
4
|
+
import { JwtModule } from "@auth0/angular-jwt";
|
|
5
|
+
import { HttpClientModule } from "@angular/common/http";
|
|
6
|
+
import { UIRouterModule } from '@uirouter/angular';
|
|
7
|
+
import { Transition, UIRouter } from '@uirouter/angular';
|
|
8
|
+
import { routerConfigFn } from './router.config';
|
|
9
|
+
import { MembrsConfigService } from './config.service';
|
|
10
|
+
import { retrieveToken } from './token';
|
|
11
|
+
export const validateResolve = {
|
|
12
|
+
token: 'reissue',
|
|
13
|
+
deps: [Transition, UIRouter, MembrsService, MembrsConfigService],
|
|
14
|
+
resolveFn: validateResolveFn
|
|
15
|
+
};
|
|
16
|
+
export const reissueResolve = {
|
|
17
|
+
token: 'reissue',
|
|
18
|
+
deps: [Transition, UIRouter, MembrsService, MembrsConfigService],
|
|
19
|
+
resolveFn: reissueResolveFn
|
|
20
|
+
};
|
|
21
|
+
export const reissueState = {
|
|
22
|
+
name: 'reissue',
|
|
23
|
+
url: '/reissue?token',
|
|
24
|
+
views: {},
|
|
25
|
+
resolve: [
|
|
26
|
+
reissueResolve
|
|
27
|
+
]
|
|
28
|
+
};
|
|
29
|
+
export function reissueResolveFn(transition, router, membrsService, membrsConfig) {
|
|
30
|
+
//console.log(membrsService)
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
console.log('reissue promise resolve');
|
|
33
|
+
console.log(transition.params().token);
|
|
34
|
+
membrsService.reissue(transition.params().token).then((response) => {
|
|
35
|
+
console.log('redirect to default state');
|
|
36
|
+
router.stateService.go(membrsConfig.defaultState, {}, { inherit: false });
|
|
37
|
+
reject();
|
|
38
|
+
}).catch(error => {
|
|
39
|
+
console.log('error in reissue resolve');
|
|
40
|
+
console.log(error);
|
|
41
|
+
//window.location.href = environment.login
|
|
42
|
+
reject(error);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export function validateResolveFn(transition, router, membrsService, membrsConfig) {
|
|
47
|
+
//console.log(membrsService)
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
console.log('validate promise resolve');
|
|
50
|
+
membrsService.reissue().then((response) => {
|
|
51
|
+
resolve();
|
|
52
|
+
}).catch(error => {
|
|
53
|
+
console.log('error in validateResolveFn');
|
|
54
|
+
console.log(error);
|
|
55
|
+
//window.location.href = membrsConfig.login
|
|
56
|
+
//reject(error)
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export function jwtOptionsFactory(config) {
|
|
61
|
+
console.log('jwt options factory');
|
|
62
|
+
console.log(config);
|
|
63
|
+
return {
|
|
64
|
+
tokenGetter: () => {
|
|
65
|
+
console.log('token getter', localStorage.getItem('membrs'));
|
|
66
|
+
return localStorage.getItem('membrs');
|
|
67
|
+
},
|
|
68
|
+
allowedDomains: [config.api]
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** The top level state(s) */
|
|
72
|
+
export const STATES = [
|
|
73
|
+
reissueState
|
|
74
|
+
];
|
|
3
75
|
export class MembrsModule {
|
|
76
|
+
static forRoot(config) {
|
|
77
|
+
const moduleProviders = UIRouterModule.forChild({
|
|
78
|
+
states: STATES,
|
|
79
|
+
config: routerConfigFn
|
|
80
|
+
}).providers;
|
|
81
|
+
moduleProviders.push(JwtModule.forRoot({
|
|
82
|
+
config: {
|
|
83
|
+
tokenGetter: retrieveToken,
|
|
84
|
+
allowedDomains: []
|
|
85
|
+
}
|
|
86
|
+
}).providers);
|
|
87
|
+
moduleProviders.push(MembrsService);
|
|
88
|
+
moduleProviders.push({ provide: MembrsConfigService, useValue: config });
|
|
89
|
+
return {
|
|
90
|
+
ngModule: MembrsModule,
|
|
91
|
+
providers: moduleProviders //[{provide: MembrsConfigService,useValue: config}]
|
|
92
|
+
};
|
|
93
|
+
}
|
|
4
94
|
}
|
|
5
95
|
MembrsModule.decorators = [
|
|
6
96
|
{ type: NgModule, args: [{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
97
|
+
imports: [
|
|
98
|
+
CommonModule,
|
|
99
|
+
HttpClientModule,
|
|
100
|
+
JwtModule
|
|
101
|
+
// JwtModule.forRoot({
|
|
102
|
+
// config: {
|
|
103
|
+
// tokenGetter: retrieveToken
|
|
104
|
+
// }
|
|
105
|
+
// })
|
|
106
|
+
// UIRouterModule.forChild({
|
|
107
|
+
// states: STATES,
|
|
108
|
+
// config: routerConfigFn,
|
|
109
|
+
// }),
|
|
110
|
+
// JwtModule.forRoot({})
|
|
111
|
+
]
|
|
10
112
|
},] }
|
|
11
113
|
];
|
|
12
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
114
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVtYnJzLm1vZHVsZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3Byb2plY3RzL21lbWJycy9zcmMvbGliL21lbWJycy5tb2R1bGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFFBQVEsRUFBaUMsTUFBTSxlQUFlLENBQUM7QUFDeEUsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLGlCQUFpQixDQUFDO0FBQy9DLE9BQU8sRUFBRSxhQUFhLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUNqRCxPQUFPLEVBQUUsU0FBUyxFQUFlLE1BQU0sb0JBQW9CLENBQUM7QUFDNUQsT0FBTyxFQUFFLGdCQUFnQixFQUFFLE1BQU0sc0JBQXNCLENBQUM7QUFDeEQsT0FBTyxFQUFFLGNBQWMsRUFBRSxNQUFNLG1CQUFtQixDQUFBO0FBR2xELE9BQU8sRUFBRSxVQUFVLEVBQUUsUUFBUSxFQUFFLE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gfSkucHJvdmlkZXJzKVxuICAgICAgXG4gICAgbW9kdWxlUHJvdmlkZXJzLnB1c2goTWVtYnJzU2VydmljZSlcbiAgICBtb2R1bGVQcm92aWRlcnMucHVzaCh7cHJvdmlkZTogTWVtYnJzQ29uZmlnU2VydmljZSx1c2VWYWx1ZTogY29uZmlnfSk7XG4gICAgXG4gICBcbiAgICByZXR1cm4ge1xuICAgICAgbmdNb2R1bGU6IE1lbWJyc01vZHVsZSwgXG4gICAgICBwcm92aWRlcnM6IG1vZHVsZVByb3ZpZGVycyAvL1t7cHJvdmlkZTogTWVtYnJzQ29uZmlnU2VydmljZSx1c2VWYWx1ZTogY29uZmlnfV1cbiAgICB9O1xuICAgIFxuICB9XG5cbn1cbiJdfQ==
|
|
@@ -1,13 +1,95 @@
|
|
|
1
|
-
import { Injectable } from '@angular/core';
|
|
1
|
+
import { Injectable, Inject } from '@angular/core';
|
|
2
|
+
import { JwtHelperService } from '@auth0/angular-jwt';
|
|
3
|
+
import { HttpClient } from '@angular/common/http';
|
|
4
|
+
import { MembrsConfigService } from './config.service';
|
|
2
5
|
import * as i0 from "@angular/core";
|
|
6
|
+
import * as i1 from "@angular/common/http";
|
|
7
|
+
import * as i2 from "./config.service";
|
|
8
|
+
const jwtService = new JwtHelperService();
|
|
3
9
|
export class MembrsService {
|
|
4
|
-
constructor() {
|
|
10
|
+
constructor(http, config) {
|
|
11
|
+
this.http = http;
|
|
12
|
+
this.config = config;
|
|
13
|
+
this._lsKey = 'membrs';
|
|
14
|
+
console.log('membrs constructor');
|
|
15
|
+
// if the token exists in local storage, retrieve it back to the service
|
|
16
|
+
if (localStorage.getItem(this._lsKey)) {
|
|
17
|
+
this.token = localStorage.getItem(this._lsKey);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
reissue(token) {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
if (!token && !this._token) {
|
|
23
|
+
console.log('reject, not logged in');
|
|
24
|
+
reject('NOT_LOGGED_IN');
|
|
25
|
+
}
|
|
26
|
+
if (token)
|
|
27
|
+
this.token = token;
|
|
28
|
+
// check stored token has not expired, or needs to be reissued soon
|
|
29
|
+
var reissueIn = this._decoded.exp - Math.floor(Date.now() / 1000);
|
|
30
|
+
// token has expired
|
|
31
|
+
if (reissueIn < 0) {
|
|
32
|
+
reject('NOT_LOGGED_IN');
|
|
33
|
+
}
|
|
34
|
+
// token expiring soon
|
|
35
|
+
if (reissueIn < 300) {
|
|
36
|
+
console.log('expires less than 300');
|
|
37
|
+
console.log(this.config);
|
|
38
|
+
this.http.post(this.config.apiProtocol + this.config.api + '/token/' + this._token, {}).subscribe((response) => {
|
|
39
|
+
console.log('reissue response');
|
|
40
|
+
console.log(response);
|
|
41
|
+
if (response.token) {
|
|
42
|
+
this.token = response.token;
|
|
43
|
+
resolve(this._token);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
console.log('error');
|
|
47
|
+
console.log(response);
|
|
48
|
+
reject('NOT_LOGGED_IN');
|
|
49
|
+
}
|
|
50
|
+
}, error => {
|
|
51
|
+
console.log(error);
|
|
52
|
+
reject('NOT_LOGGED_IN');
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
console.log('token ok');
|
|
57
|
+
resolve(this._token);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
set token(token) {
|
|
62
|
+
this._token = token;
|
|
63
|
+
localStorage.setItem(this._lsKey, token);
|
|
64
|
+
this._decoded = jwtService.decodeToken(this._token);
|
|
65
|
+
}
|
|
66
|
+
get profile() {
|
|
67
|
+
return this._decoded;
|
|
68
|
+
}
|
|
69
|
+
get admin() {
|
|
70
|
+
return this.profile.permission == 1;
|
|
71
|
+
}
|
|
72
|
+
logout() {
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
this.http.get(this.config.apiProtocol + this.config.api + '/token/' + this._token + '/delete', { responseType: 'text' }).subscribe((response) => {
|
|
75
|
+
this._token = null;
|
|
76
|
+
localStorage.removeItem(this._lsKey);
|
|
77
|
+
resolve(this.config.login);
|
|
78
|
+
//this.router.stateService.go('dashboard')
|
|
79
|
+
}, error => {
|
|
80
|
+
reject(this.config.login);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
5
84
|
}
|
|
6
|
-
MembrsService.ɵprov = i0.ɵɵdefineInjectable({ factory: function MembrsService_Factory() { return new MembrsService(); }, token: MembrsService, providedIn: "root" });
|
|
85
|
+
MembrsService.ɵprov = i0.ɵɵdefineInjectable({ factory: function MembrsService_Factory() { return new MembrsService(i0.ɵɵinject(i1.HttpClient), i0.ɵɵinject(i2.MembrsConfigService)); }, token: MembrsService, providedIn: "root" });
|
|
7
86
|
MembrsService.decorators = [
|
|
8
87
|
{ type: Injectable, args: [{
|
|
9
88
|
providedIn: 'root'
|
|
10
89
|
},] }
|
|
11
90
|
];
|
|
12
|
-
MembrsService.ctorParameters = () => [
|
|
13
|
-
|
|
91
|
+
MembrsService.ctorParameters = () => [
|
|
92
|
+
{ type: HttpClient },
|
|
93
|
+
{ type: undefined, decorators: [{ type: Inject, args: [MembrsConfigService,] }] }
|
|
94
|
+
];
|
|
95
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVtYnJzLnNlcnZpY2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9wcm9qZWN0cy9tZW1icnMvc3JjL2xpYi9tZW1icnMuc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sRUFBRSxNQUFNLGVBQWUsQ0FBQztBQUNuRCxPQUFPLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUN0RCxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sc0JBQXNCLENBQUE7QUFDakQsT0FBTyxF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ICAgLy8gdG9rZW4gaGFzIGV4cGlyZWRcbiAgICAgIGlmKHJlaXNzdWVJbiA8IDApe1xuICAgICAgICByZWplY3QoJ05PVF9MT0dHRURfSU4nKVxuICAgICAgfVxuICAgICAgXG4gICAgICAvLyB0b2tlbiBleHBpcmluZyBzb29uXG4gICAgICBpZihyZWlzc3VlSW4gPCAzMDApe1xuICAgICAgICBcbiAgICAgICAgY29uc29sZS5sb2coJ2V4cGlyZXMgbGVzcyB0aGFuIDMwMCcpXG4gICAgICAgIFxuICAgICAgICBcbiAgICAgICAgY29uc29sZS5sb2codGhpcy5jb25maWcpXG5cbiAgICAgICAgdGhpcy5odHRwLnBvc3QodGhpcy5jb25maWcuYXBpUHJvdG9jb2wgKyB0aGlzLmNvbmZpZy5hcGkrJy90b2tlbi8nK3RoaXMuX3Rva2VuLCB7fSkuc3Vic2NyaWJlKChyZXNwb25zZTphbnkpPT57XG4gICAgICAgICAgY29uc29sZS5sb2coJ3JlaXNzdWUgcmVzcG9uc2UnKVxuICAgICAgICAgIGNvbnNvbGUubG9nKHJlc3BvbnNlKVxuICAgICAgICAgIGlmKHJlc3BvbnNlLnRva2VuKXtcbiAgICAgICAgICAgIHRoaXMudG9rZW4gPSByZXNwb25zZS50b2tlblxuICAgICAgICAgICAgcmVzb2x2ZSh0aGlzLl90b2tlbilcbiAgICAgICAgICB9ZWxzZSB7XG4gICAgICAgICAgICBjb25zb2xlLmxvZygnZXJyb3InKVxuICAgICAgICAgICAgY29uc29sZS5sb2cocmVzcG9uc2UpXG4gICAgICAgICAgICByZWplY3QoJ05PVF9MT0dHRURfSU4nKVxuICAgICAgICAgIH1cbiAgICAgICAgICBcbiAgICAgICAgfSwgZXJyb3I9PntcbiAgICAgICAgICBjb25zb2xlLmxvZyhlcnJvcilcbiAgICAgICAgICByZWplY3QoJ05PVF9MT0dHRURfSU4nKVxuICAgICAgICB9KVxuXG4gICAgICB9ZWxzZSB7XG4gICAgICAgIGNvbnNvbGUubG9nKCd0b2tlb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+
import { MembrsConfigService } from './config.service';
|
|
2
|
+
export function routerConfigFn(router, injector) {
|
|
3
|
+
const transitionService = router.transitionService;
|
|
4
|
+
const stateService = router.stateService;
|
|
5
|
+
const config = injector.get(MembrsConfigService);
|
|
6
|
+
stateService.defaultErrorHandler(function (error) {
|
|
7
|
+
console.log('Default error handler - Membrs Angular Helper');
|
|
8
|
+
console.log(error);
|
|
9
|
+
if (error.detail == 'NOT_LOGGED_IN')
|
|
10
|
+
window.location.href = config.login;
|
|
11
|
+
if (error.detail == 'INSUFFICIENT_PERMISSIONS')
|
|
12
|
+
stateService.go(config.defaultState);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGVyLmNvbmZpZy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3Byb2plY3RzL21lbWJycy9zcmMvbGliL3JvdXRlci5jb25maWcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLG1CQUFtQixFQUFFLE1BQU0sa0JBQWtCLENBQUE7QUFJdEQsTUFBTSxVQUFVLGNBQWMsQ0FBQyxNQUFnQixFQUFFLFFBQWtCO0lBRWpFLE1BQU0saUJBQWlCLEdBQUcsTUFBTSxDQUFDLGlCQUFpQixDQUFDO0lBQ25ELE1BQU0sWUFBWSxHQUFHLE1BQU0sQ0FBQyxZQUFZLENBQUE7SUFDeEMsTUFBTSxNQUFNLEdBQWdCLFFBQVEsQ0FBQyxHQUFHLENBQUMsbUJBQW1CLENBQUMsQ0FBQTtJQUU3RCxZQUFZLENBQUMsbUJBQW1CLENBQUMsVUFBUyxLQUFLO1FBRS9DLE9BQU8sQ0FBQyxHQUFHLENBQUMsK0NBQStDLENBQUMsQ0FBQTtRQUM1RCxPQUFPLENBQUMsR0FBRyxDQUFDLEtBQUssQ0FBQyxDQUFBO1FBRWxC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nNvbGUubG9nKGVycm9yKVxuXHRcdFx0XG5cdFx0aWYoZXJyb3IuZGV0YWlsID09ICdOT1RfTE9HR0VEX0lOJylcblx0XHRcdHdpbmRvdy5sb2NhdGlvbi5ocmVmID0gY29uZmlnLmxvZ2luO1xuXG5cdFx0aWYoZXJyb3IuZGV0YWlsID09ICdJTlNVRkZJQ0lFTlRfUEVSTUlTU0lPTlMnKVxuXHRcdFx0c3RhdGVTZXJ2aWNlLmdvKGNvbmZpZy5kZWZhdWx0U3RhdGUpXG5cblx0fSk7XG5cdFxufSJdfQ==
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export function retrieveToken() {
|
|
2
|
+
console.log('retrieve from ls');
|
|
3
|
+
return localStorage.getItem('membrs');
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidG9rZW4uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9wcm9qZWN0cy9tZW1icnMvc3JjL2xpYi90b2tlbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxNQUFNLFVBQVUsYUFBYTtJQUN6QixPQUFPLENBQUMsR0FBRyxDQUFDLGtCQUFrQixDQUFDLENBQUE7SUFDL0IsT0FBTyxZQUFZLENBQUMsT0FBTyxDQUFDLFFBQVEsQ0FBQyxDQUFDO0FBQzFDLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZnVuY3Rpb24gcmV0cmlldmVUb2tlbigpIHtcbiAgICBjb25zb2xlLmxvZygncmV0cmlldmUgZnJvbSBscycpXG4gICAgcmV0dXJuIGxvY2FsU3RvcmFnZS5nZXRJdGVtKCdtZW1icnMnKTtcbn0iXX0=
|
|
@@ -2,4 +2,5 @@
|
|
|
2
2
|
* Generated bundle index. Do not edit.
|
|
3
3
|
*/
|
|
4
4
|
export * from './public-api';
|
|
5
|
-
|
|
5
|
+
export { MembrsConfigService as ɵa } from './lib/config.service';
|
|
6
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmFrZWRjcmVhdGl2aXR5LW1lbWJycy1hbmd1bGFyLWhlbHBlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3Byb2plY3RzL21lbWJycy9zcmMvbmFrZWRjcmVhdGl2aXR5LW1lbWJycy1hbmd1bGFyLWhlbHBlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7R0FFRztBQUVILGNBQWMsY0FBYyxDQUFDO0FBRzdCLE9BQU8sRUFBQyxtQkFBbUIsSUFBSSxFQUFFLEVBQUMsTUFBTSxzQkFBc0IsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogR2VuZXJhdGVkIGJ1bmRsZSBpbmRleC4gRG8gbm90IGVkaXQuXG4gKi9cblxuZXhwb3J0ICogZnJvbSAnLi9wdWJsaWMtYXBpJztcblxuZXhwb3J0IHtNZW1icnNDb25maWcgYXMgybVifSBmcm9tICcuL2xpYi9jb25maWcuaW50ZXJmYWNlJztcbmV4cG9ydCB7TWVtYnJzQ29uZmlnU2VydmljZSBhcyDJtWF9IGZyb20gJy4vbGliL2NvbmZpZy5zZXJ2aWNlJzsiXX0=
|
package/esm2015/public-api.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Public API Surface of membrs
|
|
3
|
-
*/
|
|
4
1
|
export * from './lib/membrs.service';
|
|
5
|
-
export * from './lib/membrs.component';
|
|
6
2
|
export * from './lib/membrs.module';
|
|
7
|
-
|
|
3
|
+
export * from './lib/token';
|
|
4
|
+
export * from './lib/auth.interceptor';
|
|
5
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljLWFwaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3Byb2plY3RzL21lbWJycy9zcmMvcHVibGljLWFwaS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxjQUFjLHNCQUFzQixDQUFDO0FBQ3JDLGNBQWMscUJBQXFCLENBQUM7QUFDcEMsY0FBYyxhQUFhLENBQUE7QUFDM0IsY0FBYyx3QkFBd0IsQ0FBQSIsInNvdXJjZXNDb250ZW50IjpbIlxuZXhwb3J0ICogZnJvbSAnLi9saWIvbWVtYnJzLnNlcnZpY2UnO1xuZXhwb3J0ICogZnJvbSAnLi9saWIvbWVtYnJzLm1vZHVsZSc7XG5leHBvcnQgKiBmcm9tICcuL2xpYi90b2tlbidcbmV4cG9ydCAqIGZyb20gJy4vbGliL2F1dGguaW50ZXJjZXB0b3InIl19
|
|
@@ -1,50 +1,249 @@
|
|
|
1
|
-
import { ɵɵdefineInjectable, Injectable,
|
|
1
|
+
import { InjectionToken, ɵɵdefineInjectable, ɵɵinject, Injectable, Inject, NgModule } from '@angular/core';
|
|
2
|
+
import { JwtHelperService, JwtModule } from '@auth0/angular-jwt';
|
|
3
|
+
import { HttpClient, HttpClientModule } from '@angular/common/http';
|
|
4
|
+
import { CommonModule } from '@angular/common';
|
|
5
|
+
import { Transition, UIRouter, UIRouterModule } from '@uirouter/angular';
|
|
6
|
+
import { finalize } from 'rxjs/operators';
|
|
2
7
|
|
|
8
|
+
/**
|
|
9
|
+
* This is not a real service, but it looks like it from the outside.
|
|
10
|
+
* It's just an InjectionTToken used to import the config object, provided from the outside
|
|
11
|
+
*/
|
|
12
|
+
const MembrsConfigService = new InjectionToken("MembrsConfig");
|
|
13
|
+
|
|
14
|
+
const jwtService = new JwtHelperService();
|
|
3
15
|
class MembrsService {
|
|
4
|
-
constructor() {
|
|
16
|
+
constructor(http, config) {
|
|
17
|
+
this.http = http;
|
|
18
|
+
this.config = config;
|
|
19
|
+
this._lsKey = 'membrs';
|
|
20
|
+
console.log('membrs constructor');
|
|
21
|
+
// if the token exists in local storage, retrieve it back to the service
|
|
22
|
+
if (localStorage.getItem(this._lsKey)) {
|
|
23
|
+
this.token = localStorage.getItem(this._lsKey);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
reissue(token) {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
if (!token && !this._token) {
|
|
29
|
+
console.log('reject, not logged in');
|
|
30
|
+
reject('NOT_LOGGED_IN');
|
|
31
|
+
}
|
|
32
|
+
if (token)
|
|
33
|
+
this.token = token;
|
|
34
|
+
// check stored token has not expired, or needs to be reissued soon
|
|
35
|
+
var reissueIn = this._decoded.exp - Math.floor(Date.now() / 1000);
|
|
36
|
+
// token has expired
|
|
37
|
+
if (reissueIn < 0) {
|
|
38
|
+
reject('NOT_LOGGED_IN');
|
|
39
|
+
}
|
|
40
|
+
// token expiring soon
|
|
41
|
+
if (reissueIn < 300) {
|
|
42
|
+
console.log('expires less than 300');
|
|
43
|
+
console.log(this.config);
|
|
44
|
+
this.http.post(this.config.apiProtocol + this.config.api + '/token/' + this._token, {}).subscribe((response) => {
|
|
45
|
+
console.log('reissue response');
|
|
46
|
+
console.log(response);
|
|
47
|
+
if (response.token) {
|
|
48
|
+
this.token = response.token;
|
|
49
|
+
resolve(this._token);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
console.log('error');
|
|
53
|
+
console.log(response);
|
|
54
|
+
reject('NOT_LOGGED_IN');
|
|
55
|
+
}
|
|
56
|
+
}, error => {
|
|
57
|
+
console.log(error);
|
|
58
|
+
reject('NOT_LOGGED_IN');
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
console.log('token ok');
|
|
63
|
+
resolve(this._token);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
set token(token) {
|
|
68
|
+
this._token = token;
|
|
69
|
+
localStorage.setItem(this._lsKey, token);
|
|
70
|
+
this._decoded = jwtService.decodeToken(this._token);
|
|
71
|
+
}
|
|
72
|
+
get profile() {
|
|
73
|
+
return this._decoded;
|
|
74
|
+
}
|
|
75
|
+
get admin() {
|
|
76
|
+
return this.profile.permission == 1;
|
|
77
|
+
}
|
|
78
|
+
logout() {
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
80
|
+
this.http.get(this.config.apiProtocol + this.config.api + '/token/' + this._token + '/delete', { responseType: 'text' }).subscribe((response) => {
|
|
81
|
+
this._token = null;
|
|
82
|
+
localStorage.removeItem(this._lsKey);
|
|
83
|
+
resolve(this.config.login);
|
|
84
|
+
//this.router.stateService.go('dashboard')
|
|
85
|
+
}, error => {
|
|
86
|
+
reject(this.config.login);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
5
90
|
}
|
|
6
|
-
MembrsService.ɵprov = ɵɵdefineInjectable({ factory: function MembrsService_Factory() { return new MembrsService(); }, token: MembrsService, providedIn: "root" });
|
|
91
|
+
MembrsService.ɵprov = ɵɵdefineInjectable({ factory: function MembrsService_Factory() { return new MembrsService(ɵɵinject(HttpClient), ɵɵinject(MembrsConfigService)); }, token: MembrsService, providedIn: "root" });
|
|
7
92
|
MembrsService.decorators = [
|
|
8
93
|
{ type: Injectable, args: [{
|
|
9
94
|
providedIn: 'root'
|
|
10
95
|
},] }
|
|
11
96
|
];
|
|
12
|
-
MembrsService.ctorParameters = () => [
|
|
97
|
+
MembrsService.ctorParameters = () => [
|
|
98
|
+
{ type: HttpClient },
|
|
99
|
+
{ type: undefined, decorators: [{ type: Inject, args: [MembrsConfigService,] }] }
|
|
100
|
+
];
|
|
13
101
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
102
|
+
function routerConfigFn(router, injector) {
|
|
103
|
+
const transitionService = router.transitionService;
|
|
104
|
+
const stateService = router.stateService;
|
|
105
|
+
const config = injector.get(MembrsConfigService);
|
|
106
|
+
stateService.defaultErrorHandler(function (error) {
|
|
107
|
+
console.log('Default error handler - Membrs Angular Helper');
|
|
108
|
+
console.log(error);
|
|
109
|
+
if (error.detail == 'NOT_LOGGED_IN')
|
|
110
|
+
window.location.href = config.login;
|
|
111
|
+
if (error.detail == 'INSUFFICIENT_PERMISSIONS')
|
|
112
|
+
stateService.go(config.defaultState);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function retrieveToken() {
|
|
117
|
+
console.log('retrieve from ls');
|
|
118
|
+
return localStorage.getItem('membrs');
|
|
18
119
|
}
|
|
19
|
-
MembrsComponent.decorators = [
|
|
20
|
-
{ type: Component, args: [{
|
|
21
|
-
selector: 'lib-membrs',
|
|
22
|
-
template: `
|
|
23
|
-
<p>
|
|
24
|
-
membrs works!
|
|
25
|
-
</p>
|
|
26
|
-
`
|
|
27
|
-
},] }
|
|
28
|
-
];
|
|
29
|
-
MembrsComponent.ctorParameters = () => [];
|
|
30
120
|
|
|
121
|
+
const validateResolve = {
|
|
122
|
+
token: 'reissue',
|
|
123
|
+
deps: [Transition, UIRouter, MembrsService, MembrsConfigService],
|
|
124
|
+
resolveFn: validateResolveFn
|
|
125
|
+
};
|
|
126
|
+
const reissueResolve = {
|
|
127
|
+
token: 'reissue',
|
|
128
|
+
deps: [Transition, UIRouter, MembrsService, MembrsConfigService],
|
|
129
|
+
resolveFn: reissueResolveFn
|
|
130
|
+
};
|
|
131
|
+
const reissueState = {
|
|
132
|
+
name: 'reissue',
|
|
133
|
+
url: '/reissue?token',
|
|
134
|
+
views: {},
|
|
135
|
+
resolve: [
|
|
136
|
+
reissueResolve
|
|
137
|
+
]
|
|
138
|
+
};
|
|
139
|
+
function reissueResolveFn(transition, router, membrsService, membrsConfig) {
|
|
140
|
+
//console.log(membrsService)
|
|
141
|
+
return new Promise((resolve, reject) => {
|
|
142
|
+
console.log('reissue promise resolve');
|
|
143
|
+
console.log(transition.params().token);
|
|
144
|
+
membrsService.reissue(transition.params().token).then((response) => {
|
|
145
|
+
console.log('redirect to default state');
|
|
146
|
+
router.stateService.go(membrsConfig.defaultState, {}, { inherit: false });
|
|
147
|
+
reject();
|
|
148
|
+
}).catch(error => {
|
|
149
|
+
console.log('error in reissue resolve');
|
|
150
|
+
console.log(error);
|
|
151
|
+
//window.location.href = environment.login
|
|
152
|
+
reject(error);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function validateResolveFn(transition, router, membrsService, membrsConfig) {
|
|
157
|
+
//console.log(membrsService)
|
|
158
|
+
return new Promise((resolve, reject) => {
|
|
159
|
+
console.log('validate promise resolve');
|
|
160
|
+
membrsService.reissue().then((response) => {
|
|
161
|
+
resolve();
|
|
162
|
+
}).catch(error => {
|
|
163
|
+
console.log('error in validateResolveFn');
|
|
164
|
+
console.log(error);
|
|
165
|
+
//window.location.href = membrsConfig.login
|
|
166
|
+
//reject(error)
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function jwtOptionsFactory(config) {
|
|
171
|
+
console.log('jwt options factory');
|
|
172
|
+
console.log(config);
|
|
173
|
+
return {
|
|
174
|
+
tokenGetter: () => {
|
|
175
|
+
console.log('token getter', localStorage.getItem('membrs'));
|
|
176
|
+
return localStorage.getItem('membrs');
|
|
177
|
+
},
|
|
178
|
+
allowedDomains: [config.api]
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/** The top level state(s) */
|
|
182
|
+
const STATES = [
|
|
183
|
+
reissueState
|
|
184
|
+
];
|
|
31
185
|
class MembrsModule {
|
|
186
|
+
static forRoot(config) {
|
|
187
|
+
const moduleProviders = UIRouterModule.forChild({
|
|
188
|
+
states: STATES,
|
|
189
|
+
config: routerConfigFn
|
|
190
|
+
}).providers;
|
|
191
|
+
moduleProviders.push(JwtModule.forRoot({
|
|
192
|
+
config: {
|
|
193
|
+
tokenGetter: retrieveToken,
|
|
194
|
+
allowedDomains: []
|
|
195
|
+
}
|
|
196
|
+
}).providers);
|
|
197
|
+
moduleProviders.push(MembrsService);
|
|
198
|
+
moduleProviders.push({ provide: MembrsConfigService, useValue: config });
|
|
199
|
+
return {
|
|
200
|
+
ngModule: MembrsModule,
|
|
201
|
+
providers: moduleProviders //[{provide: MembrsConfigService,useValue: config}]
|
|
202
|
+
};
|
|
203
|
+
}
|
|
32
204
|
}
|
|
33
205
|
MembrsModule.decorators = [
|
|
34
206
|
{ type: NgModule, args: [{
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
207
|
+
imports: [
|
|
208
|
+
CommonModule,
|
|
209
|
+
HttpClientModule,
|
|
210
|
+
JwtModule
|
|
211
|
+
// JwtModule.forRoot({
|
|
212
|
+
// config: {
|
|
213
|
+
// tokenGetter: retrieveToken
|
|
214
|
+
// }
|
|
215
|
+
// })
|
|
216
|
+
// UIRouterModule.forChild({
|
|
217
|
+
// states: STATES,
|
|
218
|
+
// config: routerConfigFn,
|
|
219
|
+
// }),
|
|
220
|
+
// JwtModule.forRoot({})
|
|
221
|
+
]
|
|
38
222
|
},] }
|
|
39
223
|
];
|
|
40
224
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
225
|
+
class TokenInterceptor {
|
|
226
|
+
constructor() { }
|
|
227
|
+
intercept(request, next) {
|
|
228
|
+
//this.busyService.busy()
|
|
229
|
+
request = request.clone({
|
|
230
|
+
setHeaders: {
|
|
231
|
+
Authorization: localStorage.getItem('membrs')
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
return next.handle(request).pipe(finalize(() => {
|
|
235
|
+
//this.busyService.finished()
|
|
236
|
+
}));
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
TokenInterceptor.decorators = [
|
|
240
|
+
{ type: Injectable }
|
|
241
|
+
];
|
|
242
|
+
TokenInterceptor.ctorParameters = () => [];
|
|
44
243
|
|
|
45
244
|
/**
|
|
46
245
|
* Generated bundle index. Do not edit.
|
|
47
246
|
*/
|
|
48
247
|
|
|
49
|
-
export {
|
|
248
|
+
export { MembrsModule, MembrsService, STATES, TokenInterceptor, jwtOptionsFactory, reissueResolve, reissueResolveFn, reissueState, retrieveToken, validateResolve, validateResolveFn, MembrsConfigService as ɵa };
|
|
50
249
|
//# sourceMappingURL=nakedcreativity-membrs-angular-helper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nakedcreativity-membrs-angular-helper.js","sources":["../../../projects/membrs/src/lib/membrs.service.ts","../../../projects/membrs/src/lib/membrs.component.ts","../../../projects/membrs/src/lib/membrs.module.ts","../../../projects/membrs/src/public-api.ts","../../../projects/membrs/src/nakedcreativity-membrs-angular-helper.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class MembrsService {\n\n constructor() { }\n}\n","import { Component, OnInit } from '@angular/core';\n\n@Component({\n selector: 'lib-membrs',\n template: `\n <p>\n membrs works!\n </p>\n `,\n styles: [\n ]\n})\nexport class MembrsComponent implements OnInit {\n\n constructor() { }\n\n ngOnInit(): void {\n }\n\n}\n","import { NgModule } from '@angular/core';\nimport { MembrsComponent } from './membrs.component';\n\n\n\n@NgModule({\n declarations: [MembrsComponent],\n imports: [\n ],\n exports: [MembrsComponent]\n})\nexport class MembrsModule { }\n","/*\n * Public API Surface of membrs\n */\n\nexport * from './lib/membrs.service';\nexport * from './lib/membrs.component';\nexport * from './lib/membrs.module';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;MAKa,aAAa;IAExB,iBAAiB;;;;YALlB,UAAU,SAAC;gBACV,UAAU,EAAE,MAAM;aACnB;;;;MCQY,eAAe;IAE1B,iBAAiB;IAEjB,QAAQ;KACP;;;YAfF,SAAS,SAAC;gBACT,QAAQ,EAAE,YAAY;gBACtB,QAAQ,EAAE;;;;GAIT;aAGF;;;;MCAY,YAAY;;;YANxB,QAAQ,SAAC;gBACR,YAAY,EAAE,CAAC,eAAe,CAAC;gBAC/B,OAAO,EAAE,EACR;gBACD,OAAO,EAAE,CAAC,eAAe,CAAC;aAC3B;;;ACVD;;;;ACAA;;;;;;"}
|
|
1
|
+
{"version":3,"file":"nakedcreativity-membrs-angular-helper.js","sources":["../../../projects/membrs/src/lib/config.service.ts","../../../projects/membrs/src/lib/membrs.service.ts","../../../projects/membrs/src/lib/router.config.ts","../../../projects/membrs/src/lib/token.ts","../../../projects/membrs/src/lib/membrs.module.ts","../../../projects/membrs/src/lib/auth.interceptor.ts","../../../projects/membrs/src/nakedcreativity-membrs-angular-helper.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\nimport { MembrsConfig } from './config.interface';\n\n/**\n * This is not a real service, but it looks like it from the outside.\n * It's just an InjectionTToken used to import the config object, provided from the outside\n */\nexport const MembrsConfigService = new InjectionToken<MembrsConfig>(\"MembrsConfig\");\n","import { Injectable, Inject } from '@angular/core';\nimport { JwtHelperService } from '@auth0/angular-jwt';\nimport { HttpClient } from '@angular/common/http'\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\nconst jwtService = new JwtHelperService()\n\n@Injectable({\n providedIn: 'root'\n})\n\n\nexport class MembrsService {\n\n _token: string;\n _decoded: any;\n _lsKey: string = 'membrs';\n\n constructor(private http: HttpClient, @Inject(MembrsConfigService) private config: MembrsConfig) {\n\n console.log('membrs constructor')\n // if the token exists in local storage, retrieve it back to the service\n if(localStorage.getItem(this._lsKey)){\n this.token = localStorage.getItem(this._lsKey)\n }\n \n }\n\n reissue(token?:string){\n\n return new Promise((resolve, reject)=>{\n\n if(!token && !this._token){\n console.log('reject, not logged in')\n reject('NOT_LOGGED_IN')\n }\n\n if(token)\n this.token = token\n\n // check stored token has not expired, or needs to be reissued soon\n var reissueIn = this._decoded.exp - Math.floor(Date.now()/1000)\n \n // token has expired\n if(reissueIn < 0){\n reject('NOT_LOGGED_IN')\n }\n \n // token expiring soon\n if(reissueIn < 300){\n \n console.log('expires less than 300')\n \n \n console.log(this.config)\n\n this.http.post(this.config.apiProtocol + this.config.api+'/token/'+this._token, {}).subscribe((response:any)=>{\n console.log('reissue response')\n console.log(response)\n if(response.token){\n this.token = response.token\n resolve(this._token)\n }else {\n console.log('error')\n console.log(response)\n reject('NOT_LOGGED_IN')\n }\n \n }, error=>{\n console.log(error)\n reject('NOT_LOGGED_IN')\n })\n\n }else {\n console.log('token ok')\n resolve(this._token)\n }\n \n })\n \n }\n\n set token(token){\n this._token = token\n localStorage.setItem(this._lsKey, token)\n this._decoded = jwtService.decodeToken(this._token)\n }\n\n get profile(){\n return this._decoded\n }\n\n get admin (){\n return this.profile.permission == 1\n }\n\n logout(){\n return new Promise((resolve, reject)=>{\n this.http.get(this.config.apiProtocol+this.config.api+'/token/'+this._token+'/delete', {responseType: 'text'}).subscribe((response:any)=>{\n this._token = null;\n localStorage.removeItem(this._lsKey)\n resolve(this.config.login)\n //this.router.stateService.go('dashboard')\n }, error=>{\n reject(this.config.login)\n })\n })\n \n }\n\n\n}\n","import { UIRouter } from '@uirouter/core';\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\nimport { Injector } from '@angular/core';\n\nexport function routerConfigFn(router: UIRouter, injector: Injector) {\n\n const transitionService = router.transitionService;\n const stateService = router.stateService\n const config:MembrsConfig = injector.get(MembrsConfigService)\n\n \tstateService.defaultErrorHandler(function(error) {\n\t\t \n\t\tconsole.log('Default error handler - Membrs Angular Helper')\n\t\tconsole.log(error)\n\t\t\t\n\t\tif(error.detail == 'NOT_LOGGED_IN')\n\t\t\twindow.location.href = config.login;\n\n\t\tif(error.detail == 'INSUFFICIENT_PERMISSIONS')\n\t\t\tstateService.go(config.defaultState)\n\n\t});\n\t\n}","export function retrieveToken() {\n console.log('retrieve from ls')\n return localStorage.getItem('membrs');\n}","import { NgModule, ModuleWithProviders, Injector } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { MembrsService } from './membrs.service';\nimport { JwtModule, JWT_OPTIONS } from \"@auth0/angular-jwt\";\nimport { HttpClientModule } from \"@angular/common/http\";\nimport { UIRouterModule } from '@uirouter/angular'\n\nimport { Ng2StateDeclaration } from '@uirouter/angular';\nimport { Transition, UIRouter } from '@uirouter/angular'\n\nimport { routerConfigFn } from './router.config';\nimport { MembrsConfig } from './config.interface';\nimport { MembrsConfigService } from './config.service';\nimport { retrieveToken } from './token';\n\nexport const validateResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService, MembrsConfigService ],\n resolveFn: validateResolveFn\n}\n\nexport const reissueResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService, MembrsConfigService ],\n resolveFn: reissueResolveFn\n}\n\nexport const reissueState:Ng2StateDeclaration = {\n\tname: 'reissue', \n\turl: '/reissue?token',\n\tviews: { },\n\tresolve: [\n reissueResolve\n\t]\n}\n\nexport function reissueResolveFn(transition, router, membrsService, membrsConfig:MembrsConfig) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('reissue promise resolve')\n console.log(transition.params().token)\n membrsService.reissue(transition.params().token).then((response)=>{\n console.log('redirect to default state')\n router.stateService.go(membrsConfig.defaultState, {}, {inherit:false})\n reject()\n }).catch(error=>{\n console.log('error in reissue resolve')\n console.log(error)\n //window.location.href = environment.login\n reject(error)\n })\n\n\t})\n}\n\nexport function validateResolveFn(transition, router, membrsService, membrsConfig:MembrsConfig) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('validate promise resolve')\n \n membrsService.reissue().then((response)=>{\n resolve()\n }).catch(error=>{\n console.log('error in validateResolveFn')\n console.log(error)\n //window.location.href = membrsConfig.login\n //reject(error)\n })\n\n})\n}\n\nexport function jwtOptionsFactory(config) {\n console.log('jwt options factory')\n console.log(config)\n return {\n tokenGetter: () => {\n console.log('token getter', localStorage.getItem('membrs'))\n return localStorage.getItem('membrs');\n },\n allowedDomains: [config.api]\n }\n}\n\n\n/** The top level state(s) */\nexport const STATES = [\n reissueState\n]\n\n\n@NgModule({\n imports: [\n CommonModule,\n HttpClientModule,\n JwtModule\n // JwtModule.forRoot({\n // config: {\n // tokenGetter: retrieveToken\n // }\n // })\n // UIRouterModule.forChild({\n // states: STATES,\n // config: routerConfigFn,\n // }),\n // JwtModule.forRoot({})\n ]\n})\n\n\n\nexport class MembrsModule { \n static forRoot(config: MembrsConfig): ModuleWithProviders<MembrsModule> {\n\n\n const moduleProviders = UIRouterModule.forChild({\n states: STATES,\n config: routerConfigFn\n }).providers\n\n moduleProviders.push(JwtModule.forRoot({\n config: {\n tokenGetter: retrieveToken,\n allowedDomains: []\n }\n }).providers)\n \n moduleProviders.push(MembrsService)\n moduleProviders.push({provide: MembrsConfigService,useValue: config});\n \n \n return {\n ngModule: MembrsModule, \n providers: moduleProviders //[{provide: MembrsConfigService,useValue: config}]\n };\n \n }\n\n}\n","import { Injectable } from '@angular/core';\nimport {\n HttpRequest,\n HttpHandler,\n HttpEvent,\n HttpInterceptor\n} from '@angular/common/http';\nimport { Observable } from 'rxjs';\n//import { NgBusyService } from '@nakedcreativity/ng-busy';\nimport { finalize } from 'rxjs/operators';\n\n\n@Injectable()\nexport class TokenInterceptor implements HttpInterceptor {\n constructor() {}\n intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n \n //this.busyService.busy()\n request = request.clone({\n setHeaders: {\n Authorization: localStorage.getItem('membrs')\n }\n });\n return next.handle(request).pipe(finalize(()=>{\n //this.busyService.finished()\n }));\n }\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n\nexport {MembrsConfig as ɵb} from './lib/config.interface';\nexport {MembrsConfigService as ɵa} from './lib/config.service';"],"names":[],"mappings":";;;;;;;AAGA;;;;MAIa,mBAAmB,GAAG,IAAI,cAAc,CAAe,cAAc;;ACFlF,MAAM,UAAU,GAAG,IAAI,gBAAgB,EAAE,CAAA;MAO5B,aAAa;IAMxB,YAAoB,IAAgB,EAAuC,MAAoB;QAA3E,SAAI,GAAJ,IAAI,CAAY;QAAuC,WAAM,GAAN,MAAM,CAAc;QAF/F,WAAM,GAAW,QAAQ,CAAC;QAIxB,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,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;oBACP,YAAY;oBACZ,gBAAgB;oBAChB,SAAS;;;;;;;;;;;iBAWV;aACF;;;MChGY,gBAAgB;IAC3B,iBAAgB;IAChB,SAAS,CAAC,OAAyB,EAAE,IAAiB;;QAGpD,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC;YACtB,UAAU,EAAE;gBACV,aAAa,EAAE,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC;aAC9C;SACF,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC;;SAEzC,CAAC,CAAC,CAAC;KACL;;;YAdF,UAAU;;;;ACZX;;;;;;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
export declare class TokenInterceptor implements HttpInterceptor {
|
|
4
|
+
constructor();
|
|
5
|
+
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
import { MembrsConfig } from './config.interface';
|
|
3
|
+
/**
|
|
4
|
+
* This is not a real service, but it looks like it from the outside.
|
|
5
|
+
* It's just an InjectionTToken used to import the config object, provided from the outside
|
|
6
|
+
*/
|
|
7
|
+
export declare const MembrsConfigService: InjectionToken<MembrsConfig>;
|
package/lib/membrs.module.d.ts
CHANGED
|
@@ -1,2 +1,27 @@
|
|
|
1
|
+
import { ModuleWithProviders } from '@angular/core';
|
|
2
|
+
import { MembrsService } from './membrs.service';
|
|
3
|
+
import { Ng2StateDeclaration } from '@uirouter/angular';
|
|
4
|
+
import { Transition, UIRouter } from '@uirouter/angular';
|
|
5
|
+
import { MembrsConfig } from './config.interface';
|
|
6
|
+
export declare const validateResolve: {
|
|
7
|
+
token: string;
|
|
8
|
+
deps: (import("@angular/core").InjectionToken<MembrsConfig> | typeof MembrsService | typeof Transition | typeof UIRouter)[];
|
|
9
|
+
resolveFn: typeof validateResolveFn;
|
|
10
|
+
};
|
|
11
|
+
export declare const reissueResolve: {
|
|
12
|
+
token: string;
|
|
13
|
+
deps: (import("@angular/core").InjectionToken<MembrsConfig> | typeof MembrsService | typeof Transition | typeof UIRouter)[];
|
|
14
|
+
resolveFn: typeof reissueResolveFn;
|
|
15
|
+
};
|
|
16
|
+
export declare const reissueState: Ng2StateDeclaration;
|
|
17
|
+
export declare function reissueResolveFn(transition: any, router: any, membrsService: any, membrsConfig: MembrsConfig): Promise<unknown>;
|
|
18
|
+
export declare function validateResolveFn(transition: any, router: any, membrsService: any, membrsConfig: MembrsConfig): Promise<unknown>;
|
|
19
|
+
export declare function jwtOptionsFactory(config: any): {
|
|
20
|
+
tokenGetter: () => string;
|
|
21
|
+
allowedDomains: any[];
|
|
22
|
+
};
|
|
23
|
+
/** The top level state(s) */
|
|
24
|
+
export declare const STATES: Ng2StateDeclaration[];
|
|
1
25
|
export declare class MembrsModule {
|
|
26
|
+
static forRoot(config: MembrsConfig): ModuleWithProviders<MembrsModule>;
|
|
2
27
|
}
|
package/lib/membrs.service.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
import { HttpClient } from '@angular/common/http';
|
|
2
|
+
import { MembrsConfig } from './config.interface';
|
|
1
3
|
export declare class MembrsService {
|
|
2
|
-
|
|
4
|
+
private http;
|
|
5
|
+
private config;
|
|
6
|
+
_token: string;
|
|
7
|
+
_decoded: any;
|
|
8
|
+
_lsKey: string;
|
|
9
|
+
constructor(http: HttpClient, config: MembrsConfig);
|
|
10
|
+
reissue(token?: string): Promise<unknown>;
|
|
11
|
+
set token(token: any);
|
|
12
|
+
get profile(): any;
|
|
13
|
+
get admin(): boolean;
|
|
14
|
+
logout(): Promise<unknown>;
|
|
3
15
|
}
|
package/lib/token.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function retrieveToken(): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"__symbolic":"module","version":4,"metadata":{"MembrsService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":
|
|
1
|
+
{"__symbolic":"module","version":4,"metadata":{"MembrsService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":7,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[null,[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":18,"character":41},"arguments":[{"__symbolic":"reference","name":"ɵa"}]}]],"parameters":[{"__symbolic":"reference","module":"@angular/common/http","name":"HttpClient","line":18,"character":28},{"__symbolic":"reference","name":"ɵb"}]}],"reissue":[{"__symbolic":"method"}],"logout":[{"__symbolic":"method"}]},"statics":{"ɵprov":{}}},"validateResolve":{"token":"reissue","deps":[{"__symbolic":"reference","module":"@uirouter/angular","name":"Transition","line":17,"character":12},{"__symbolic":"reference","module":"@uirouter/angular","name":"UIRouter","line":17,"character":24},{"__symbolic":"reference","name":"MembrsService"},{"__symbolic":"reference","name":"ɵa"}],"resolveFn":{"__symbolic":"reference","name":"validateResolveFn"}},"reissueResolve":{"token":"reissue","deps":[{"__symbolic":"reference","module":"@uirouter/angular","name":"Transition","line":23,"character":10},{"__symbolic":"reference","module":"@uirouter/angular","name":"UIRouter","line":23,"character":22},{"__symbolic":"reference","name":"MembrsService"},{"__symbolic":"reference","name":"ɵa"}],"resolveFn":{"__symbolic":"reference","name":"reissueResolveFn"}},"reissueState":{"name":"reissue","url":"/reissue?token","views":{},"resolve":[{"__symbolic":"reference","name":"reissueResolve"}]},"reissueResolveFn":{"__symbolic":"function","parameters":["transition","router","membrsService","membrsConfig"],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"Promise"},"arguments":[{"__symbolic":"error","message":"Lambda not supported","line":39,"character":23,"module":"./lib/membrs.module"}]}},"validateResolveFn":{"__symbolic":"function","parameters":["transition","router","membrsService","membrsConfig"],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"Promise"},"arguments":[{"__symbolic":"error","message":"Lambda not supported","line":59,"character":21,"module":"./lib/membrs.module"}]}},"jwtOptionsFactory":{"__symbolic":"function"},"STATES":[{"__symbolic":"reference","name":"reissueState"}],"MembrsModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":93,"character":1},"arguments":[{"imports":[{"__symbolic":"reference","module":"@angular/common","name":"CommonModule","line":95,"character":4},{"__symbolic":"reference","module":"@angular/common/http","name":"HttpClientModule","line":96,"character":4},{"__symbolic":"reference","module":"@auth0/angular-jwt","name":"JwtModule","line":97,"character":4}]}]}],"members":{}},"retrieveToken":{"__symbolic":"function"},"TokenInterceptor":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":12,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor"}],"intercept":[{"__symbolic":"method"}]}},"ɵa":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":7,"character":39},"arguments":["MembrsConfig"]},"ɵb":{"__symbolic":"interface"}},"origins":{"MembrsService":"./lib/membrs.service","validateResolve":"./lib/membrs.module","reissueResolve":"./lib/membrs.module","reissueState":"./lib/membrs.module","reissueResolveFn":"./lib/membrs.module","validateResolveFn":"./lib/membrs.module","jwtOptionsFactory":"./lib/membrs.module","STATES":"./lib/membrs.module","MembrsModule":"./lib/membrs.module","retrieveToken":"./lib/token","TokenInterceptor":"./lib/auth.interceptor","ɵa":"./lib/config.service","ɵb":"./lib/config.interface"},"importAs":"@nakedcreativity/membrs-angular-helper"}
|
package/package.json
CHANGED
package/public-api.d.ts
CHANGED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Component } from '@angular/core';
|
|
2
|
-
export class MembrsComponent {
|
|
3
|
-
constructor() { }
|
|
4
|
-
ngOnInit() {
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
MembrsComponent.decorators = [
|
|
8
|
-
{ type: Component, args: [{
|
|
9
|
-
selector: 'lib-membrs',
|
|
10
|
-
template: `
|
|
11
|
-
<p>
|
|
12
|
-
membrs works!
|
|
13
|
-
</p>
|
|
14
|
-
`
|
|
15
|
-
},] }
|
|
16
|
-
];
|
|
17
|
-
MembrsComponent.ctorParameters = () => [];
|
|
18
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVtYnJzLmNvbXBvbmVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3Byb2plY3RzL21lbWJycy9zcmMvbGliL21lbWJycy5jb21wb25lbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFNBQVMsRUFBVSxNQUFNLGVBQWUsQ0FBQztBQVlsRCxNQUFNLE9BQU8sZUFBZTtJQUUxQixnQkFBZ0IsQ0FBQztJQUVqQixRQUFRO0lBQ1IsQ0FBQzs7O1lBZkYsU0FBUyxTQUFDO2dCQUNULFFBQVEsRUFBRSxZQUFZO2dCQUN0QixRQUFRLEVBQUU7Ozs7R0FJVDthQUdGIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgQ29tcG9uZW50LCBPbkluaXQgfSBmcm9tICdAYW5ndWxhci9jb3JlJztcblxuQENvbXBvbmVudCh7XG4gIHNlbGVjdG9yOiAnbGliLW1lbWJycycsXG4gIHRlbXBsYXRlOiBgXG4gICAgPHA+XG4gICAgICBtZW1icnMgd29ya3MhXG4gICAgPC9wPlxuICBgLFxuICBzdHlsZXM6IFtcbiAgXVxufSlcbmV4cG9ydCBjbGFzcyBNZW1icnNDb21wb25lbnQgaW1wbGVtZW50cyBPbkluaXQge1xuXG4gIGNvbnN0cnVjdG9yKCkgeyB9XG5cbiAgbmdPbkluaXQoKTogdm9pZCB7XG4gIH1cblxufVxuIl19
|