@gandalan/weblibs 1.0.1 → 1.0.3

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/api/IDAS.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { RESTClient } from './RESTClient';
2
+ import jwt_decode from 'jwt-decode';
2
3
 
3
4
  let appToken = localStorage.getItem('IDAS_AppToken') || '66B70E0B-F7C4-4829-B12A-18AD309E3970';
4
5
  let authToken = localStorage.getItem('IDAS_AuthToken');
@@ -51,7 +52,7 @@ class IDAS {
51
52
 
52
53
  // still not valid JWT -> authenticate
53
54
  if (!refreshClient.token) {
54
- localStorage.setItem('IDAS_AuthJwtCallbackPath', authPath);
55
+ localStorage.setItem('IDAS_AuthJwtCallbackPath', authPath || '');
55
56
  const authEndpoint = (new URL(window.location.href).origin) + authPath;
56
57
  let authUrlCallback = `${authEndpoint}?r=%target%&t=%jwt%&m=%mandant%`;
57
58
  authUrlCallback = authUrlCallback.replace('%target%', encodeURIComponent(window.location.href));
@@ -72,6 +73,37 @@ class IDAS {
72
73
 
73
74
  mandantGuid = localStorage.getItem('IDAS_MandantGuid');
74
75
 
76
+ claims = {
77
+ hasClaim(key) {
78
+ if (!authJwtToken) {
79
+ return false;
80
+ }
81
+
82
+ try {
83
+ let decoded = jwt_decode(authJwtToken);
84
+ let val = decoded[key];
85
+ return val !== undefined;
86
+ }
87
+ catch {}
88
+
89
+ return false;
90
+ },
91
+
92
+ getClaim(key) {
93
+ if (!authJwtToken) {
94
+ return;
95
+ }
96
+
97
+ try {
98
+ let decoded = jwt_decode(authJwtToken);
99
+ return decoded[key];
100
+ }
101
+ catch {}
102
+
103
+ return;
104
+ }
105
+ }
106
+
75
107
  auth = {
76
108
  _self: this,
77
109
  async getCurrentAuthToken() {
package/api/RESTClient.js CHANGED
@@ -86,7 +86,7 @@ export class RESTClient {
86
86
 
87
87
  updateJwtToken(jwt) {
88
88
  let decoded = jwt_decode(jwt);
89
- let refreshToken = decoded['refreshToken'];
89
+ let refreshToken = decoded['refreshToken'] || '';
90
90
  localStorage.setItem('IDAS_AuthJwtRefreshToken', refreshToken);
91
91
  authJwtRefreshToken = refreshToken;
92
92
  this.token = jwt;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gandalan/weblibs",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "WebLibs for Gandalan JS/TS/Svelte projects",
5
5
  "author": "Philipp Reif",
6
6
  "license": "ISC",