piral-oidc 1.6.0-beta.7240 → 1.6.0-beta.7244
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/lib/OidcError.js +5 -9
- package/lib/OidcError.js.map +1 -1
- package/lib/create.js +1 -5
- package/lib/create.js.map +1 -1
- package/lib/index.js +3 -6
- package/lib/index.js.map +1 -1
- package/lib/setup.js +25 -29
- package/lib/setup.js.map +1 -1
- package/lib/types.js +4 -7
- package/lib/types.js.map +1 -1
- package/package.json +9 -20
- package/esm/OidcError.d.ts +0 -13
- package/esm/OidcError.js +0 -30
- package/esm/OidcError.js.map +0 -1
- package/esm/create.d.ts +0 -6
- package/esm/create.js +0 -17
- package/esm/create.js.map +0 -1
- package/esm/index.d.ts +0 -3
- package/esm/index.js +0 -4
- package/esm/index.js.map +0 -1
- package/esm/setup.d.ts +0 -6
- package/esm/setup.js +0 -200
- package/esm/setup.js.map +0 -1
- package/esm/types.d.ts +0 -270
- package/esm/types.js +0 -61
- package/esm/types.js.map +0 -1
package/lib/OidcError.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OidcError = void 0;
|
|
4
|
-
const types_1 = require("./types");
|
|
1
|
+
import { OidcErrorType } from './types';
|
|
5
2
|
const errorMessageMap = {
|
|
6
|
-
[
|
|
7
|
-
[
|
|
8
|
-
[
|
|
3
|
+
[OidcErrorType.notAuthorized]: 'Not logged in. Please call `login()` to retrieve a token.',
|
|
4
|
+
[OidcErrorType.silentRenewFailed]: 'Silent renew failed to retrieve access token.',
|
|
5
|
+
[OidcErrorType.invalidToken]: 'Invalid token during authentication',
|
|
9
6
|
};
|
|
10
7
|
const getErrorMessage = (type, innerError) => {
|
|
11
8
|
const message = errorMessageMap[type];
|
|
@@ -18,7 +15,7 @@ const getErrorMessage = (type, innerError) => {
|
|
|
18
15
|
* An optional innerError can be supplied in order to not lose visibility on messages provided
|
|
19
16
|
* by oidc-client.
|
|
20
17
|
*/
|
|
21
|
-
class OidcError extends Error {
|
|
18
|
+
export class OidcError extends Error {
|
|
22
19
|
constructor(errorType, innerError) {
|
|
23
20
|
const message = getErrorMessage(errorType, innerError);
|
|
24
21
|
super(message);
|
|
@@ -30,5 +27,4 @@ class OidcError extends Error {
|
|
|
30
27
|
this.innerError = innerError;
|
|
31
28
|
}
|
|
32
29
|
}
|
|
33
|
-
exports.OidcError = OidcError;
|
|
34
30
|
//# sourceMappingURL=OidcError.js.map
|
package/lib/OidcError.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcError.js","sourceRoot":"","sources":["../src/OidcError.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"OidcError.js","sourceRoot":"","sources":["../src/OidcError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAkB,MAAM,SAAS,CAAC;AAExD,MAAM,eAAe,GAAG;IACtB,CAAC,aAAa,CAAC,aAAa,CAAC,EAAE,2DAA2D;IAC1F,CAAC,aAAa,CAAC,iBAAiB,CAAC,EAAE,+CAA+C;IAClF,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE,qCAAqC;CACpE,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,IAAmB,EAAE,UAA2B,EAAE,EAAE;IAC3E,MAAM,OAAO,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACtC,OAAO,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,oDAAoD,CAAC,CAAC;AAChH,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAIlC,YAAY,SAAwB,EAAE,UAA2B;QAC/D,MAAM,OAAO,GAAG,eAAe,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,KAAK,CAAC,iBAAiB,EAAE;YAC3B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;SAC1C;QAED,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF"}
|
package/lib/create.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createOidcApi = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Creates new Pilet API extensions for the integration of OpenID Connect.
|
|
6
3
|
*/
|
|
7
|
-
function createOidcApi(client) {
|
|
4
|
+
export function createOidcApi(client) {
|
|
8
5
|
return (context) => {
|
|
9
6
|
context.on('before-fetch', client.extendHeaders);
|
|
10
7
|
return {
|
|
@@ -17,5 +14,4 @@ function createOidcApi(client) {
|
|
|
17
14
|
};
|
|
18
15
|
};
|
|
19
16
|
}
|
|
20
|
-
exports.createOidcApi = createOidcApi;
|
|
21
17
|
//# sourceMappingURL=create.js.map
|
package/lib/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MAAkB;IAC9C,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,OAAO,CAAC,EAAE,CAAC,cAAc,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;QAEjD,OAAO;YACL,cAAc;gBACZ,OAAO,MAAM,CAAC,KAAK,EAAE,CAAC;YACxB,CAAC;YAED,UAAU;gBACR,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC;YAC1B,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
tslib_1.__exportStar(require("./create"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./setup"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./types"), exports);
|
|
1
|
+
export * from './create';
|
|
2
|
+
export * from './setup';
|
|
3
|
+
export * from './types';
|
|
7
4
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
package/lib/setup.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const oidc_client_1 = require("oidc-client");
|
|
5
|
-
const OidcError_1 = require("./OidcError");
|
|
6
|
-
const types_1 = require("./types");
|
|
1
|
+
import { Log, UserManager } from 'oidc-client';
|
|
2
|
+
import { OidcError } from './OidcError';
|
|
3
|
+
import { LogLevel, OidcErrorType } from './types';
|
|
7
4
|
const logLevelToOidcMap = {
|
|
8
|
-
[
|
|
9
|
-
[
|
|
10
|
-
[
|
|
11
|
-
[
|
|
12
|
-
[
|
|
5
|
+
[LogLevel.none]: 0,
|
|
6
|
+
[LogLevel.error]: 1,
|
|
7
|
+
[LogLevel.warn]: 2,
|
|
8
|
+
[LogLevel.info]: 3,
|
|
9
|
+
[LogLevel.debug]: 4,
|
|
13
10
|
};
|
|
14
11
|
function doesWindowLocationMatch(targetUri) {
|
|
15
12
|
return window.location.pathname === new URL(targetUri).pathname;
|
|
@@ -21,10 +18,10 @@ function convertLogLevelToOidcClient(level) {
|
|
|
21
18
|
* Sets up a new client wrapping the oidc-client API.
|
|
22
19
|
* @param config The configuration for the client.
|
|
23
20
|
*/
|
|
24
|
-
function setupOidcClient(config) {
|
|
21
|
+
export function setupOidcClient(config) {
|
|
25
22
|
const { clientId, clientSecret, identityProviderUri, redirectUri = `${location.origin}/auth`, signInRedirectParams, postLogoutRedirectUri = location.origin, responseType, responseMode, scopes, restrict = false, parentName, appUri, logLevel, userStore, extraQueryParams, uiLocales, metadata, metadataUrl, monitorSession, } = config;
|
|
26
23
|
const isMainWindow = () => (parentName ? parentName === window.parent?.name : window === window.top);
|
|
27
|
-
const userManager = new
|
|
24
|
+
const userManager = new UserManager({
|
|
28
25
|
authority: identityProviderUri,
|
|
29
26
|
redirect_uri: redirectUri,
|
|
30
27
|
silent_redirect_uri: redirectUri,
|
|
@@ -43,12 +40,12 @@ function setupOidcClient(config) {
|
|
|
43
40
|
monitorSession,
|
|
44
41
|
});
|
|
45
42
|
if (logLevel !== undefined) {
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
Log.logger = console;
|
|
44
|
+
Log.level = convertLogLevelToOidcClient(logLevel);
|
|
48
45
|
}
|
|
49
46
|
else if (process.env.NODE_ENV === 'development') {
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
Log.logger = console;
|
|
48
|
+
Log.level = Log.DEBUG;
|
|
52
49
|
}
|
|
53
50
|
if (doesWindowLocationMatch(userManager.settings.post_logout_redirect_uri)) {
|
|
54
51
|
if (isMainWindow()) {
|
|
@@ -64,7 +61,7 @@ function setupOidcClient(config) {
|
|
|
64
61
|
.getUser()
|
|
65
62
|
.then((user) => {
|
|
66
63
|
if (!user) {
|
|
67
|
-
rej(new
|
|
64
|
+
rej(new OidcError(OidcErrorType.notAuthorized));
|
|
68
65
|
}
|
|
69
66
|
else if (user.access_token && user.expires_in > 60) {
|
|
70
67
|
res(user.access_token);
|
|
@@ -72,28 +69,28 @@ function setupOidcClient(config) {
|
|
|
72
69
|
else {
|
|
73
70
|
return userManager.signinSilent().then((user) => {
|
|
74
71
|
if (!user) {
|
|
75
|
-
return rej(new
|
|
72
|
+
return rej(new OidcError(OidcErrorType.silentRenewFailed));
|
|
76
73
|
}
|
|
77
74
|
if (!user.access_token) {
|
|
78
|
-
return rej(new
|
|
75
|
+
return rej(new OidcError(OidcErrorType.invalidToken));
|
|
79
76
|
}
|
|
80
77
|
return res(user.access_token);
|
|
81
78
|
});
|
|
82
79
|
}
|
|
83
80
|
})
|
|
84
|
-
.catch((err) => rej(new
|
|
81
|
+
.catch((err) => rej(new OidcError(OidcErrorType.unknown, err)));
|
|
85
82
|
});
|
|
86
83
|
};
|
|
87
84
|
const retrieveProfile = () => {
|
|
88
85
|
return new Promise((res, rej) => {
|
|
89
86
|
userManager.getUser().then((user) => {
|
|
90
87
|
if (!user || user.expires_in <= 0) {
|
|
91
|
-
return rej(new
|
|
88
|
+
return rej(new OidcError(OidcErrorType.notAuthorized));
|
|
92
89
|
}
|
|
93
90
|
else {
|
|
94
91
|
return res(user.profile);
|
|
95
92
|
}
|
|
96
|
-
}, (err) => rej(new
|
|
93
|
+
}, (err) => rej(new OidcError(OidcErrorType.unknown, err)));
|
|
97
94
|
});
|
|
98
95
|
};
|
|
99
96
|
const handleAuthentication = () => new Promise(async (resolve, reject) => {
|
|
@@ -111,7 +108,7 @@ function setupOidcClient(config) {
|
|
|
111
108
|
user = await userManager.signinSilentCallback();
|
|
112
109
|
}
|
|
113
110
|
catch (e) {
|
|
114
|
-
return reject(new
|
|
111
|
+
return reject(new OidcError(OidcErrorType.oidcCallback, e));
|
|
115
112
|
}
|
|
116
113
|
return resolve({
|
|
117
114
|
shouldRender: false,
|
|
@@ -127,10 +124,10 @@ function setupOidcClient(config) {
|
|
|
127
124
|
* Failing to handle a sign-in callback is non-recoverable. The user is expected to call `logout()`, after
|
|
128
125
|
* logging this error to their internal error-handling service. Usually, this is due to a misconfigured auth server.
|
|
129
126
|
*/
|
|
130
|
-
return reject(new
|
|
127
|
+
return reject(new OidcError(OidcErrorType.oidcCallback, e));
|
|
131
128
|
}
|
|
132
129
|
if (appUri) {
|
|
133
|
-
|
|
130
|
+
Log.debug(`Redirecting to ${appUri} due to appUri being configured.`);
|
|
134
131
|
window.location.href = appUri;
|
|
135
132
|
return resolve({
|
|
136
133
|
shouldRender: false,
|
|
@@ -155,11 +152,11 @@ function setupOidcClient(config) {
|
|
|
155
152
|
}
|
|
156
153
|
else {
|
|
157
154
|
/* We should never get into this state, retrieveToken() should reject if there is no token */
|
|
158
|
-
return reject(new
|
|
155
|
+
return reject(new OidcError(OidcErrorType.invalidToken));
|
|
159
156
|
}
|
|
160
157
|
})
|
|
161
158
|
.catch(async (reason) => {
|
|
162
|
-
if (reason.type ===
|
|
159
|
+
if (reason.type === OidcErrorType.notAuthorized) {
|
|
163
160
|
/*
|
|
164
161
|
* Expected Error during normal code flow:
|
|
165
162
|
* This is the first time logging in since a logout (or ever), instead of asking the user
|
|
@@ -200,5 +197,4 @@ function setupOidcClient(config) {
|
|
|
200
197
|
account: retrieveProfile,
|
|
201
198
|
};
|
|
202
199
|
}
|
|
203
|
-
exports.setupOidcClient = setupOidcClient;
|
|
204
200
|
//# sourceMappingURL=setup.js.map
|
package/lib/setup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAQ,WAAW,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAwB,QAAQ,EAA0B,aAAa,EAAe,MAAM,SAAS,CAAC;AAE7G,MAAM,iBAAiB,GAAG;IACxB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;IAClB,CAAC,QAAQ,CAAC,KAAK,CAAC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object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OidcErrorType = exports.LogLevel = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* The available log levels.
|
|
6
3
|
*/
|
|
7
|
-
var LogLevel;
|
|
4
|
+
export var LogLevel;
|
|
8
5
|
(function (LogLevel) {
|
|
9
6
|
/**
|
|
10
7
|
* Logging disabled.
|
|
@@ -26,11 +23,11 @@ var LogLevel;
|
|
|
26
23
|
* Log everything - good for debugging purposes.
|
|
27
24
|
*/
|
|
28
25
|
LogLevel["debug"] = "debug";
|
|
29
|
-
})(LogLevel || (
|
|
26
|
+
})(LogLevel || (LogLevel = {}));
|
|
30
27
|
/**
|
|
31
28
|
* The available error types.
|
|
32
29
|
*/
|
|
33
|
-
var OidcErrorType;
|
|
30
|
+
export var OidcErrorType;
|
|
34
31
|
(function (OidcErrorType) {
|
|
35
32
|
/**
|
|
36
33
|
* This error was thrown at some point during authentication, by the browser or by oidc-client
|
|
@@ -60,5 +57,5 @@ var OidcErrorType;
|
|
|
60
57
|
* prompted to logout().
|
|
61
58
|
*/
|
|
62
59
|
OidcErrorType["oidcCallback"] = "oidcCallback";
|
|
63
|
-
})(OidcErrorType || (
|
|
60
|
+
})(OidcErrorType || (OidcErrorType = {}));
|
|
64
61
|
//# sourceMappingURL=types.js.map
|
package/lib/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAuGA;;GAEG;AACH,MAAM,CAAN,IAAY,QAqBX;AArBD,WAAY,QAAQ;IAClB;;OAEG;IACH,yBAAa,CAAA;IACb;;OAEG;IACH,2BAAe,CAAA;IACf;;OAEG;IACH,yBAAa,CAAA;IACb;;OAEG;IACH,yBAAa,CAAA;IACb;;OAEG;IACH,2BAAe,CAAA;AACjB,CAAC,EArBW,QAAQ,KAAR,QAAQ,QAqBnB;AA8FD;;GAEG;AACH,MAAM,CAAN,IAAY,aA6BX;AA7BD,WAAY,aAAa;IACvB;;;OAGG;IACH,oCAAmB,CAAA;IACnB;;;;OAIG;IACH,gDAA+B,CAAA;IAC/B;;;OAGG;IACH,wDAAuC,CAAA;IACvC;;;;OAIG;IACH,8CAA6B,CAAA;IAC7B;;;;OAIG;IACH,8CAA6B,CAAA;AAC/B,CAAC,EA7BW,aAAa,KAAb,aAAa,QA6BxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-oidc",
|
|
3
|
-
"version": "1.6.0-beta.
|
|
3
|
+
"version": "1.6.0-beta.7244",
|
|
4
4
|
"description": "Plugin to integrate authentication using OpenID connect in Piral.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"piral",
|
|
@@ -19,29 +19,19 @@
|
|
|
19
19
|
"author": "smapiot",
|
|
20
20
|
"homepage": "https://piral.io",
|
|
21
21
|
"license": "MIT",
|
|
22
|
-
"module": "
|
|
22
|
+
"module": "lib/index.js",
|
|
23
23
|
"main": "lib/index.js",
|
|
24
24
|
"typings": "lib/index.d.ts",
|
|
25
25
|
"exports": {
|
|
26
|
-
".":
|
|
27
|
-
"import": "./esm/index.js",
|
|
28
|
-
"require": "./lib/index.js"
|
|
29
|
-
},
|
|
30
|
-
"./esm/*": {
|
|
31
|
-
"import": "./esm/*"
|
|
32
|
-
},
|
|
26
|
+
".": "./lib/index.js",
|
|
33
27
|
"./lib/*": {
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
"./_/*": {
|
|
37
|
-
"import": "./esm/*.js",
|
|
38
|
-
"require": "./lib/*.js"
|
|
28
|
+
"import": "./lib/*",
|
|
29
|
+
"types": "./lib/*.d.ts"
|
|
39
30
|
},
|
|
40
31
|
"./package.json": "./package.json"
|
|
41
32
|
},
|
|
42
33
|
"sideEffects": false,
|
|
43
34
|
"files": [
|
|
44
|
-
"esm",
|
|
45
35
|
"lib",
|
|
46
36
|
"src",
|
|
47
37
|
"piral-oidc.min.js"
|
|
@@ -55,10 +45,9 @@
|
|
|
55
45
|
},
|
|
56
46
|
"scripts": {
|
|
57
47
|
"cleanup": "rimraf esm lib piral-oidc.min.js",
|
|
58
|
-
"build": "yarn build:bundle && yarn build:
|
|
48
|
+
"build": "yarn build:bundle && yarn build:esnext",
|
|
59
49
|
"build:bundle": "esbuild src/index.ts --outfile=piral-oidc.min.js --bundle --external:piral-core --minify --global-name=piralOidc",
|
|
60
|
-
"build:
|
|
61
|
-
"build:esnext": "tsc --project tsconfig.json --outDir esm --module esnext",
|
|
50
|
+
"build:esnext": "tsc --project tsconfig.json --outDir lib --module esnext",
|
|
62
51
|
"typedoc": "typedoc --json ../../../docs/types/piral-oidc.json src --exclude \"src/**/*.test.*\"",
|
|
63
52
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
64
53
|
},
|
|
@@ -66,7 +55,7 @@
|
|
|
66
55
|
"oidc-client": "^1.10.1"
|
|
67
56
|
},
|
|
68
57
|
"devDependencies": {
|
|
69
|
-
"piral-core": "1.6.0-beta.
|
|
58
|
+
"piral-core": "1.6.0-beta.7244"
|
|
70
59
|
},
|
|
71
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "65ac1291c3429dbf16079b4deb6138b24c5719f7"
|
|
72
61
|
}
|
package/esm/OidcError.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { OidcErrorType, PiralOidcError } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* A custom error class for oidc errors. It is important to use this class
|
|
4
|
-
* instead of generic Errors, as some application paths inspect `OidcError['type']`.
|
|
5
|
-
*
|
|
6
|
-
* An optional innerError can be supplied in order to not lose visibility on messages provided
|
|
7
|
-
* by oidc-client.
|
|
8
|
-
*/
|
|
9
|
-
export declare class OidcError extends Error implements PiralOidcError {
|
|
10
|
-
readonly type: any;
|
|
11
|
-
readonly innerError: any;
|
|
12
|
-
constructor(errorType: OidcErrorType, innerError?: Error | string);
|
|
13
|
-
}
|
package/esm/OidcError.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { OidcErrorType } from './types';
|
|
2
|
-
const errorMessageMap = {
|
|
3
|
-
[OidcErrorType.notAuthorized]: 'Not logged in. Please call `login()` to retrieve a token.',
|
|
4
|
-
[OidcErrorType.silentRenewFailed]: 'Silent renew failed to retrieve access token.',
|
|
5
|
-
[OidcErrorType.invalidToken]: 'Invalid token during authentication',
|
|
6
|
-
};
|
|
7
|
-
const getErrorMessage = (type, innerError) => {
|
|
8
|
-
const message = errorMessageMap[type];
|
|
9
|
-
return message || (innerError ? innerError.toString() : 'an unexpected error has occurred without a message');
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* A custom error class for oidc errors. It is important to use this class
|
|
13
|
-
* instead of generic Errors, as some application paths inspect `OidcError['type']`.
|
|
14
|
-
*
|
|
15
|
-
* An optional innerError can be supplied in order to not lose visibility on messages provided
|
|
16
|
-
* by oidc-client.
|
|
17
|
-
*/
|
|
18
|
-
export class OidcError extends Error {
|
|
19
|
-
constructor(errorType, innerError) {
|
|
20
|
-
const message = getErrorMessage(errorType, innerError);
|
|
21
|
-
super(message);
|
|
22
|
-
if (Error.captureStackTrace) {
|
|
23
|
-
Error.captureStackTrace(this, OidcError);
|
|
24
|
-
}
|
|
25
|
-
this.name = 'OidcError';
|
|
26
|
-
this.type = errorType;
|
|
27
|
-
this.innerError = innerError;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=OidcError.js.map
|
package/esm/OidcError.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"OidcError.js","sourceRoot":"","sources":["../src/OidcError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAkB,MAAM,SAAS,CAAC;AAExD,MAAM,eAAe,GAAG;IACtB,CAAC,aAAa,CAAC,aAAa,CAAC,EAAE,2DAA2D;IAC1F,CAAC,aAAa,CAAC,iBAAiB,CAAC,EAAE,+CAA+C;IAClF,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE,qCAAqC;CACpE,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,IAAmB,EAAE,UAA2B,EAAE,EAAE;IAC3E,MAAM,OAAO,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACtC,OAAO,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,oDAAoD,CAAC,CAAC;AAChH,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAIlC,YAAY,SAAwB,EAAE,UAA2B;QAC/D,MAAM,OAAO,GAAG,eAAe,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,KAAK,CAAC,iBAAiB,EAAE;YAC3B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;SAC1C;QAED,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF"}
|
package/esm/create.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { PiralPlugin } from 'piral-core';
|
|
2
|
-
import { PiletOidcApi, OidcClient } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Creates new Pilet API extensions for the integration of OpenID Connect.
|
|
5
|
-
*/
|
|
6
|
-
export declare function createOidcApi(client: OidcClient): PiralPlugin<PiletOidcApi>;
|
package/esm/create.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates new Pilet API extensions for the integration of OpenID Connect.
|
|
3
|
-
*/
|
|
4
|
-
export function createOidcApi(client) {
|
|
5
|
-
return (context) => {
|
|
6
|
-
context.on('before-fetch', client.extendHeaders);
|
|
7
|
-
return {
|
|
8
|
-
getAccessToken() {
|
|
9
|
-
return client.token();
|
|
10
|
-
},
|
|
11
|
-
getProfile() {
|
|
12
|
-
return client.account();
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=create.js.map
|
package/esm/create.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MAAkB;IAC9C,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,OAAO,CAAC,EAAE,CAAC,cAAc,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;QAEjD,OAAO;YACL,cAAc;gBACZ,OAAO,MAAM,CAAC,KAAK,EAAE,CAAC;YACxB,CAAC;YAED,UAAU;gBACR,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC;YAC1B,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
package/esm/index.d.ts
DELETED
package/esm/index.js
DELETED
package/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
package/esm/setup.d.ts
DELETED
package/esm/setup.js
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { Log, UserManager } from 'oidc-client';
|
|
2
|
-
import { OidcError } from './OidcError';
|
|
3
|
-
import { LogLevel, OidcErrorType } from './types';
|
|
4
|
-
const logLevelToOidcMap = {
|
|
5
|
-
[LogLevel.none]: 0,
|
|
6
|
-
[LogLevel.error]: 1,
|
|
7
|
-
[LogLevel.warn]: 2,
|
|
8
|
-
[LogLevel.info]: 3,
|
|
9
|
-
[LogLevel.debug]: 4,
|
|
10
|
-
};
|
|
11
|
-
function doesWindowLocationMatch(targetUri) {
|
|
12
|
-
return window.location.pathname === new URL(targetUri).pathname;
|
|
13
|
-
}
|
|
14
|
-
function convertLogLevelToOidcClient(level) {
|
|
15
|
-
return logLevelToOidcMap[level];
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Sets up a new client wrapping the oidc-client API.
|
|
19
|
-
* @param config The configuration for the client.
|
|
20
|
-
*/
|
|
21
|
-
export function setupOidcClient(config) {
|
|
22
|
-
const { clientId, clientSecret, identityProviderUri, redirectUri = `${location.origin}/auth`, signInRedirectParams, postLogoutRedirectUri = location.origin, responseType, responseMode, scopes, restrict = false, parentName, appUri, logLevel, userStore, extraQueryParams, uiLocales, metadata, metadataUrl, monitorSession, } = config;
|
|
23
|
-
const isMainWindow = () => (parentName ? parentName === window.parent?.name : window === window.top);
|
|
24
|
-
const userManager = new UserManager({
|
|
25
|
-
authority: identityProviderUri,
|
|
26
|
-
redirect_uri: redirectUri,
|
|
27
|
-
silent_redirect_uri: redirectUri,
|
|
28
|
-
popup_redirect_uri: redirectUri,
|
|
29
|
-
post_logout_redirect_uri: postLogoutRedirectUri,
|
|
30
|
-
client_id: clientId,
|
|
31
|
-
client_secret: clientSecret,
|
|
32
|
-
response_type: responseType,
|
|
33
|
-
scope: scopes?.join(' '),
|
|
34
|
-
userStore,
|
|
35
|
-
extraQueryParams,
|
|
36
|
-
ui_locales: uiLocales,
|
|
37
|
-
response_mode: responseMode,
|
|
38
|
-
metadata,
|
|
39
|
-
metadataUrl,
|
|
40
|
-
monitorSession,
|
|
41
|
-
});
|
|
42
|
-
if (logLevel !== undefined) {
|
|
43
|
-
Log.logger = console;
|
|
44
|
-
Log.level = convertLogLevelToOidcClient(logLevel);
|
|
45
|
-
}
|
|
46
|
-
else if (process.env.NODE_ENV === 'development') {
|
|
47
|
-
Log.logger = console;
|
|
48
|
-
Log.level = Log.DEBUG;
|
|
49
|
-
}
|
|
50
|
-
if (doesWindowLocationMatch(userManager.settings.post_logout_redirect_uri)) {
|
|
51
|
-
if (isMainWindow()) {
|
|
52
|
-
userManager.signoutRedirectCallback();
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
userManager.signoutPopupCallback();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
const retrieveToken = () => {
|
|
59
|
-
return new Promise((res, rej) => {
|
|
60
|
-
userManager
|
|
61
|
-
.getUser()
|
|
62
|
-
.then((user) => {
|
|
63
|
-
if (!user) {
|
|
64
|
-
rej(new OidcError(OidcErrorType.notAuthorized));
|
|
65
|
-
}
|
|
66
|
-
else if (user.access_token && user.expires_in > 60) {
|
|
67
|
-
res(user.access_token);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
return userManager.signinSilent().then((user) => {
|
|
71
|
-
if (!user) {
|
|
72
|
-
return rej(new OidcError(OidcErrorType.silentRenewFailed));
|
|
73
|
-
}
|
|
74
|
-
if (!user.access_token) {
|
|
75
|
-
return rej(new OidcError(OidcErrorType.invalidToken));
|
|
76
|
-
}
|
|
77
|
-
return res(user.access_token);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
.catch((err) => rej(new OidcError(OidcErrorType.unknown, err)));
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
const retrieveProfile = () => {
|
|
85
|
-
return new Promise((res, rej) => {
|
|
86
|
-
userManager.getUser().then((user) => {
|
|
87
|
-
if (!user || user.expires_in <= 0) {
|
|
88
|
-
return rej(new OidcError(OidcErrorType.notAuthorized));
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
return res(user.profile);
|
|
92
|
-
}
|
|
93
|
-
}, (err) => rej(new OidcError(OidcErrorType.unknown, err)));
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
const handleAuthentication = () => new Promise(async (resolve, reject) => {
|
|
97
|
-
/** The user that is resolved when finishing the callback */
|
|
98
|
-
let user;
|
|
99
|
-
if ((doesWindowLocationMatch(userManager.settings.silent_redirect_uri) ||
|
|
100
|
-
doesWindowLocationMatch(userManager.settings.popup_redirect_uri)) &&
|
|
101
|
-
!isMainWindow()) {
|
|
102
|
-
/*
|
|
103
|
-
* This is a silent redirect frame. The correct behavior is to notify the parent of the updated user,
|
|
104
|
-
* and then to do nothing else. Encountering an error here means the background IFrame failed
|
|
105
|
-
* to update the parent. This is usually due to a timeout from a network error.
|
|
106
|
-
*/
|
|
107
|
-
try {
|
|
108
|
-
user = await userManager.signinSilentCallback();
|
|
109
|
-
}
|
|
110
|
-
catch (e) {
|
|
111
|
-
return reject(new OidcError(OidcErrorType.oidcCallback, e));
|
|
112
|
-
}
|
|
113
|
-
return resolve({
|
|
114
|
-
shouldRender: false,
|
|
115
|
-
state: user?.state,
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
if (doesWindowLocationMatch(userManager.settings.redirect_uri) && isMainWindow()) {
|
|
119
|
-
try {
|
|
120
|
-
user = await userManager.signinCallback();
|
|
121
|
-
}
|
|
122
|
-
catch (e) {
|
|
123
|
-
/*
|
|
124
|
-
* Failing to handle a sign-in callback is non-recoverable. The user is expected to call `logout()`, after
|
|
125
|
-
* logging this error to their internal error-handling service. Usually, this is due to a misconfigured auth server.
|
|
126
|
-
*/
|
|
127
|
-
return reject(new OidcError(OidcErrorType.oidcCallback, e));
|
|
128
|
-
}
|
|
129
|
-
if (appUri) {
|
|
130
|
-
Log.debug(`Redirecting to ${appUri} due to appUri being configured.`);
|
|
131
|
-
window.location.href = appUri;
|
|
132
|
-
return resolve({
|
|
133
|
-
shouldRender: false,
|
|
134
|
-
state: user?.state,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
/* If appUri is not configured, we let the user decide what to do after getting a session. */
|
|
138
|
-
return resolve({
|
|
139
|
-
shouldRender: true,
|
|
140
|
-
state: user?.state,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
/*
|
|
144
|
-
* The current page is a normal flow, not a callback or signout. We should retrieve the current access_token,
|
|
145
|
-
* or log the user in if there is no current session.
|
|
146
|
-
* This branch of code should also tell the user to render the main application.
|
|
147
|
-
*/
|
|
148
|
-
return retrieveToken()
|
|
149
|
-
.then((token) => {
|
|
150
|
-
if (token) {
|
|
151
|
-
return resolve({ shouldRender: true });
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
/* We should never get into this state, retrieveToken() should reject if there is no token */
|
|
155
|
-
return reject(new OidcError(OidcErrorType.invalidToken));
|
|
156
|
-
}
|
|
157
|
-
})
|
|
158
|
-
.catch(async (reason) => {
|
|
159
|
-
if (reason.type === OidcErrorType.notAuthorized) {
|
|
160
|
-
/*
|
|
161
|
-
* Expected Error during normal code flow:
|
|
162
|
-
* This is the first time logging in since a logout (or ever), instead of asking the user
|
|
163
|
-
* to call `login()`, just perform it ourself here.
|
|
164
|
-
*
|
|
165
|
-
* The resolve shouldn't matter, as `signinRedirect` will redirect the browser location
|
|
166
|
-
* to the user's configured redirectUri.
|
|
167
|
-
*/
|
|
168
|
-
await userManager.signinRedirect(signInRedirectParams);
|
|
169
|
-
return resolve({ shouldRender: false });
|
|
170
|
-
}
|
|
171
|
-
/*
|
|
172
|
-
* Getting here is a non-recoverable error. It is up to the user to determine what to do.
|
|
173
|
-
* Usually this is a result of failing to reach the authentication server, or a misconfigured
|
|
174
|
-
* authentication server, or a bad clock skew (commonly caused by docker in windows).
|
|
175
|
-
*/
|
|
176
|
-
return reject(reason);
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
return {
|
|
180
|
-
_: userManager,
|
|
181
|
-
login() {
|
|
182
|
-
return userManager.signinRedirect(signInRedirectParams);
|
|
183
|
-
},
|
|
184
|
-
logout() {
|
|
185
|
-
return userManager.signoutRedirect();
|
|
186
|
-
},
|
|
187
|
-
revoke() {
|
|
188
|
-
return userManager.revokeAccessToken();
|
|
189
|
-
},
|
|
190
|
-
handleAuthentication,
|
|
191
|
-
extendHeaders(req) {
|
|
192
|
-
if (!restrict) {
|
|
193
|
-
req.setHeaders(retrieveToken().then((token) => token && { Authorization: `Bearer ${token}` }, () => undefined));
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
token: retrieveToken,
|
|
197
|
-
account: retrieveProfile,
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
//# sourceMappingURL=setup.js.map
|
package/esm/setup.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAQ,WAAW,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAwB,QAAQ,EAA0B,aAAa,EAAe,MAAM,SAAS,CAAC;AAE7G,MAAM,iBAAiB,GAAG;IACxB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;IAClB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;IACnB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;IAClB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;IAClB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;CACpB,CAAC;AAEF,SAAS,uBAAuB,CAAC,SAAiB;IAChD,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,KAAK,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC;AAClE,CAAC;AAED,SAAS,2BAA2B,CAAC,KAAe;IAClD,OAAO,iBAAiB,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,MAAkB;IAChD,MAAM,EACJ,QAAQ,EACR,YAAY,EACZ,mBAAmB,EACnB,WAAW,GAAG,GAAG,QAAQ,CAAC,MAAM,OAAO,EACvC,oBAAoB,EACpB,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,CAAC,EAAE,WAAW;QACd,KAAK;YACH,OAAO,WAAW,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC;QAC1D,CAAC;QACD,MAAM;YACJ,OAAO,WAAW,CAAC,eAAe,EAAE,CAAC;QACvC,CAAC;QACD,MAAM;YACJ,OAAO,WAAW,CAAC,iBAAiB,EAAE,CAAC;QACzC,CAAC;QACD,oBAAoB;QACpB,aAAa,CAAC,GAAG;YACf,IAAI,CAAC,QAAQ,EAAE;gBACb,GAAG,CAAC,UAAU,CACZ,aAAa,EAAE,CAAC,IAAI,CAClB,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,aAAa,EAAE,UAAU,KAAK,EAAE,EAAE,EACxD,GAAG,EAAE,CAAC,SAAS,CAChB,CACF,CAAC;aACH;QACH,CAAC;QACD,KAAK,EAAE,aAAa;QACpB,OAAO,EAAE,eAAe;KACzB,CAAC;AACJ,CAAC"}
|
package/esm/types.d.ts
DELETED
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
import type { Profile, StateStore } from 'oidc-client';
|
|
2
|
-
/**
|
|
3
|
-
* Available configuration options for the OpenID Connect plugin.
|
|
4
|
-
*/
|
|
5
|
-
export interface OidcConfig {
|
|
6
|
-
/**
|
|
7
|
-
* The id of the client. Required for the setup of OAuth 2.0.
|
|
8
|
-
*/
|
|
9
|
-
clientId: string;
|
|
10
|
-
/**
|
|
11
|
-
* The client secret.
|
|
12
|
-
*/
|
|
13
|
-
clientSecret?: string;
|
|
14
|
-
/**
|
|
15
|
-
* The name of the parent frame if the app is placed in an
|
|
16
|
-
* iframe.
|
|
17
|
-
*
|
|
18
|
-
* If undefined or an empty string is provided then no iframe
|
|
19
|
-
* (default behavior) is assumed.
|
|
20
|
-
*
|
|
21
|
-
* Note: This is necessary in order to avoid problems with
|
|
22
|
-
* the silent refresh when being used in an iframe.
|
|
23
|
-
*/
|
|
24
|
-
parentName?: string;
|
|
25
|
-
/**
|
|
26
|
-
* The Uri pointing to the Identity Provider.
|
|
27
|
-
*/
|
|
28
|
-
identityProviderUri: string;
|
|
29
|
-
/**
|
|
30
|
-
* The redirect Uri to use. By default the origin with /auth
|
|
31
|
-
* is used.
|
|
32
|
-
*/
|
|
33
|
-
redirectUri?: string;
|
|
34
|
-
/**
|
|
35
|
-
* Query params that will be passed to the sign in redirect
|
|
36
|
-
*/
|
|
37
|
-
signInRedirectParams?: SignInRedirectParams;
|
|
38
|
-
/**
|
|
39
|
-
* The Uri to which the Identity provider should redirect
|
|
40
|
-
* after a logout. By default the origin is used.
|
|
41
|
-
*/
|
|
42
|
-
postLogoutRedirectUri?: string;
|
|
43
|
-
/**
|
|
44
|
-
* The protocol response type to be used. By default, `id_token`
|
|
45
|
-
* is used.
|
|
46
|
-
*/
|
|
47
|
-
responseType?: string;
|
|
48
|
-
/**
|
|
49
|
-
* The response mode, which is usually already configured well
|
|
50
|
-
* via the responseType. By default, the responseType `code` will
|
|
51
|
-
* get `query` and responseType `token` will get `fragment`.
|
|
52
|
-
*/
|
|
53
|
-
responseMode?: string;
|
|
54
|
-
/**
|
|
55
|
-
* The scopes to be used. By default, `openid` is used.
|
|
56
|
-
*/
|
|
57
|
-
scopes?: Array<string>;
|
|
58
|
-
/**
|
|
59
|
-
* Restricts token sharing such that other integrations, e.g., with
|
|
60
|
-
* fetch would need to be done manually.
|
|
61
|
-
* Otherwise, the client is responsive to the `before-fetch` event.
|
|
62
|
-
*/
|
|
63
|
-
restrict?: boolean;
|
|
64
|
-
/**
|
|
65
|
-
* If provided, the window will redirect to this Uri after getting
|
|
66
|
-
* a new session from the redirectUri callback.
|
|
67
|
-
*/
|
|
68
|
-
appUri?: string;
|
|
69
|
-
/**
|
|
70
|
-
* If provided, logging will be enabled for the oidc-client.
|
|
71
|
-
* Defaults to Log.DEBUG in development NODE_ENV.
|
|
72
|
-
*/
|
|
73
|
-
logLevel?: LogLevel;
|
|
74
|
-
/**
|
|
75
|
-
* The store where user information will be placed after authentication succeeds
|
|
76
|
-
* This defaults to oidc-client's WebStorageStateStore, using sessionStorage as the internal store
|
|
77
|
-
*/
|
|
78
|
-
userStore?: OidcStore;
|
|
79
|
-
/**
|
|
80
|
-
* Provides some extra query parameters. These are included in the authorization request.
|
|
81
|
-
*/
|
|
82
|
-
extraQueryParams?: Record<string, any>;
|
|
83
|
-
/**
|
|
84
|
-
* Sets the optiopnal ui_locales parameter to set the language of the login page.
|
|
85
|
-
*/
|
|
86
|
-
uiLocales?: string;
|
|
87
|
-
/**
|
|
88
|
-
* Sets the metadata if the OIDC service does not allow querying it for whatever reason.
|
|
89
|
-
*/
|
|
90
|
-
metadata?: any;
|
|
91
|
-
/**
|
|
92
|
-
* Overrides the default metadata URL if the server does not follow the standard paths.
|
|
93
|
-
*/
|
|
94
|
-
metadataUrl?: string;
|
|
95
|
-
/**
|
|
96
|
-
* Determines if the OIDCS session should be automatically monitored.
|
|
97
|
-
*/
|
|
98
|
-
monitorSession?: boolean;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* The available log levels.
|
|
102
|
-
*/
|
|
103
|
-
export declare enum LogLevel {
|
|
104
|
-
/**
|
|
105
|
-
* Logging disabled.
|
|
106
|
-
*/
|
|
107
|
-
none = "none",
|
|
108
|
-
/**
|
|
109
|
-
* Only log on error.
|
|
110
|
-
*/
|
|
111
|
-
error = "error",
|
|
112
|
-
/**
|
|
113
|
-
* Start logging when its at least a warning.
|
|
114
|
-
*/
|
|
115
|
-
warn = "warn",
|
|
116
|
-
/**
|
|
117
|
-
* Already start logging on info level.
|
|
118
|
-
*/
|
|
119
|
-
info = "info",
|
|
120
|
-
/**
|
|
121
|
-
* Log everything - good for debugging purposes.
|
|
122
|
-
*/
|
|
123
|
-
debug = "debug"
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* This interface is used to merge in custom OIDC Claims to the
|
|
127
|
-
* `getProfile()` call. It can be used as follows below.
|
|
128
|
-
*
|
|
129
|
-
* (in this example, `piletApi.getProfile()` will return an object
|
|
130
|
-
* with the default OIDC claims, and also contain `myCustomClaim`):
|
|
131
|
-
*
|
|
132
|
-
* ```
|
|
133
|
-
* //piral-instance/index.tsx
|
|
134
|
-
* import 'piral-oidc';
|
|
135
|
-
*
|
|
136
|
-
* declare module 'piral-oidc/lib/types' {
|
|
137
|
-
* interface PiralCustomOidcProfile {
|
|
138
|
-
* myCustomClaim: string;
|
|
139
|
-
* }
|
|
140
|
-
* }
|
|
141
|
-
* ```
|
|
142
|
-
*/
|
|
143
|
-
export interface PiralCustomOidcProfile {
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* The defined OIDC profile.
|
|
147
|
-
*/
|
|
148
|
-
export type OidcProfile = PiralCustomOidcProfile & Profile;
|
|
149
|
-
export interface OidcRequest {
|
|
150
|
-
/**
|
|
151
|
-
* Sets the headers of the request.
|
|
152
|
-
* @param headers Headers or a promise to headers.
|
|
153
|
-
*/
|
|
154
|
-
setHeaders(headers: any): void;
|
|
155
|
-
}
|
|
156
|
-
export interface OidcClient {
|
|
157
|
-
/**
|
|
158
|
-
* The underlying OIDC client.
|
|
159
|
-
*/
|
|
160
|
-
_: any;
|
|
161
|
-
/**
|
|
162
|
-
* Performs a login. Will do nothing when called from a non-top window.
|
|
163
|
-
*/
|
|
164
|
-
login(): Promise<void>;
|
|
165
|
-
/**
|
|
166
|
-
* Performs a logout.
|
|
167
|
-
*/
|
|
168
|
-
logout(): Promise<void>;
|
|
169
|
-
/**
|
|
170
|
-
* Revokes the access token.
|
|
171
|
-
*/
|
|
172
|
-
revoke(): Promise<void>;
|
|
173
|
-
/**
|
|
174
|
-
* Performs a login when the app needs a new token, handles callbacks when on
|
|
175
|
-
* a callback URL, and redirects into the app route if the client was configured with an `appUri`.
|
|
176
|
-
*
|
|
177
|
-
* When this resolves to true, the app-shell should call its `render()` method.
|
|
178
|
-
* When this resolves to false, do not call `render()`.
|
|
179
|
-
*
|
|
180
|
-
* If this rejects, the app-shell should redirect to the login page or handle
|
|
181
|
-
* an authentication failure manually, it is also advised to log this error to a logging service,
|
|
182
|
-
* as no users will be be authorized to enter the application.
|
|
183
|
-
*/
|
|
184
|
-
handleAuthentication(): Promise<AuthenticationResult>;
|
|
185
|
-
/**
|
|
186
|
-
* Retrieves the current user profile.
|
|
187
|
-
*/
|
|
188
|
-
account(): Promise<OidcProfile>;
|
|
189
|
-
/**
|
|
190
|
-
* Gets a token.
|
|
191
|
-
*/
|
|
192
|
-
token(): Promise<string>;
|
|
193
|
-
/**
|
|
194
|
-
* Extends the headers of the provided request.
|
|
195
|
-
*/
|
|
196
|
-
extendHeaders(req: OidcRequest): void;
|
|
197
|
-
}
|
|
198
|
-
export interface PiletOidcApi {
|
|
199
|
-
/**
|
|
200
|
-
* Gets the currently valid access token, if any.
|
|
201
|
-
*/
|
|
202
|
-
getAccessToken(): Promise<string | undefined>;
|
|
203
|
-
/**
|
|
204
|
-
* Gets the user's claims from oidc.
|
|
205
|
-
*/
|
|
206
|
-
getProfile(): Promise<OidcProfile>;
|
|
207
|
-
}
|
|
208
|
-
declare module 'piral-core/lib/types/custom' {
|
|
209
|
-
interface PiletCustomApi extends PiletOidcApi {
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* The available error types.
|
|
214
|
-
*/
|
|
215
|
-
export declare enum OidcErrorType {
|
|
216
|
-
/**
|
|
217
|
-
* This error was thrown at some point during authentication, by the browser or by oidc-client
|
|
218
|
-
* and we are unable to handle it.
|
|
219
|
-
*/
|
|
220
|
-
unknown = "unknown",
|
|
221
|
-
/**
|
|
222
|
-
* This error happens when the user does not have an access token during Authentication.
|
|
223
|
-
* It is an expected error, and should be handled during `handleAuthentication()` calls.
|
|
224
|
-
* If doing manual authentication, prompt the user to `login()` when receiving it.
|
|
225
|
-
*/
|
|
226
|
-
notAuthorized = "notAuthorized",
|
|
227
|
-
/**
|
|
228
|
-
* This error happens when silent renew fails in the background. It is not expected, and
|
|
229
|
-
* signifies a network error or configuration problem.
|
|
230
|
-
*/
|
|
231
|
-
silentRenewFailed = "silentRenewFailed",
|
|
232
|
-
/**
|
|
233
|
-
* This is an unexpected error that happens when the `token()` call retrieves a User from
|
|
234
|
-
* the user manager, but it does not have an access_token. This signifies a configuration
|
|
235
|
-
* error, make sure the correct `scopes` are supplied during configuration.
|
|
236
|
-
*/
|
|
237
|
-
invalidToken = "invalidToken",
|
|
238
|
-
/**
|
|
239
|
-
* This error happened during an Open ID callback. This signifies a network or configuration error
|
|
240
|
-
* which is non-recoverable. This should be logged to a logging service, and the user should be
|
|
241
|
-
* prompted to logout().
|
|
242
|
-
*/
|
|
243
|
-
oidcCallback = "oidcCallback"
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* This Error is used for Authentication errors in piral-oidc.
|
|
247
|
-
*/
|
|
248
|
-
export interface PiralOidcError extends Error {
|
|
249
|
-
type: Readonly<OidcErrorType>;
|
|
250
|
-
}
|
|
251
|
-
export interface SignInRedirectParams {
|
|
252
|
-
/**
|
|
253
|
-
* Values used to maintain state between the sign in request and the callback.
|
|
254
|
-
* These will be available on the result from the handleAuthentication function
|
|
255
|
-
* successfully authenticates from a callback state.
|
|
256
|
-
*/
|
|
257
|
-
state?: any;
|
|
258
|
-
}
|
|
259
|
-
/** Result that is returned from the handleAuthentication function */
|
|
260
|
-
export interface AuthenticationResult {
|
|
261
|
-
/** Whether or not the application should be rendered */
|
|
262
|
-
shouldRender: boolean;
|
|
263
|
-
/** The request state that is returned from any callbacks.
|
|
264
|
-
* This will only be populated if a callback method is called.
|
|
265
|
-
*/
|
|
266
|
-
state?: any;
|
|
267
|
-
}
|
|
268
|
-
/** An expected interface type for oidc-client to store its user state. */
|
|
269
|
-
export interface OidcStore extends StateStore {
|
|
270
|
-
}
|
package/esm/types.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The available log levels.
|
|
3
|
-
*/
|
|
4
|
-
export var LogLevel;
|
|
5
|
-
(function (LogLevel) {
|
|
6
|
-
/**
|
|
7
|
-
* Logging disabled.
|
|
8
|
-
*/
|
|
9
|
-
LogLevel["none"] = "none";
|
|
10
|
-
/**
|
|
11
|
-
* Only log on error.
|
|
12
|
-
*/
|
|
13
|
-
LogLevel["error"] = "error";
|
|
14
|
-
/**
|
|
15
|
-
* Start logging when its at least a warning.
|
|
16
|
-
*/
|
|
17
|
-
LogLevel["warn"] = "warn";
|
|
18
|
-
/**
|
|
19
|
-
* Already start logging on info level.
|
|
20
|
-
*/
|
|
21
|
-
LogLevel["info"] = "info";
|
|
22
|
-
/**
|
|
23
|
-
* Log everything - good for debugging purposes.
|
|
24
|
-
*/
|
|
25
|
-
LogLevel["debug"] = "debug";
|
|
26
|
-
})(LogLevel || (LogLevel = {}));
|
|
27
|
-
/**
|
|
28
|
-
* The available error types.
|
|
29
|
-
*/
|
|
30
|
-
export var OidcErrorType;
|
|
31
|
-
(function (OidcErrorType) {
|
|
32
|
-
/**
|
|
33
|
-
* This error was thrown at some point during authentication, by the browser or by oidc-client
|
|
34
|
-
* and we are unable to handle it.
|
|
35
|
-
*/
|
|
36
|
-
OidcErrorType["unknown"] = "unknown";
|
|
37
|
-
/**
|
|
38
|
-
* This error happens when the user does not have an access token during Authentication.
|
|
39
|
-
* It is an expected error, and should be handled during `handleAuthentication()` calls.
|
|
40
|
-
* If doing manual authentication, prompt the user to `login()` when receiving it.
|
|
41
|
-
*/
|
|
42
|
-
OidcErrorType["notAuthorized"] = "notAuthorized";
|
|
43
|
-
/**
|
|
44
|
-
* This error happens when silent renew fails in the background. It is not expected, and
|
|
45
|
-
* signifies a network error or configuration problem.
|
|
46
|
-
*/
|
|
47
|
-
OidcErrorType["silentRenewFailed"] = "silentRenewFailed";
|
|
48
|
-
/**
|
|
49
|
-
* This is an unexpected error that happens when the `token()` call retrieves a User from
|
|
50
|
-
* the user manager, but it does not have an access_token. This signifies a configuration
|
|
51
|
-
* error, make sure the correct `scopes` are supplied during configuration.
|
|
52
|
-
*/
|
|
53
|
-
OidcErrorType["invalidToken"] = "invalidToken";
|
|
54
|
-
/**
|
|
55
|
-
* This error happened during an Open ID callback. This signifies a network or configuration error
|
|
56
|
-
* which is non-recoverable. This should be logged to a logging service, and the user should be
|
|
57
|
-
* prompted to logout().
|
|
58
|
-
*/
|
|
59
|
-
OidcErrorType["oidcCallback"] = "oidcCallback";
|
|
60
|
-
})(OidcErrorType || (OidcErrorType = {}));
|
|
61
|
-
//# sourceMappingURL=types.js.map
|
package/esm/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAuGA;;GAEG;AACH,MAAM,CAAN,IAAY,QAqBX;AArBD,WAAY,QAAQ;IAClB;;OAEG;IACH,yBAAa,CAAA;IACb;;OAEG;IACH,2BAAe,CAAA;IACf;;OAEG;IACH,yBAAa,CAAA;IACb;;OAEG;IACH,yBAAa,CAAA;IACb;;OAEG;IACH,2BAAe,CAAA;AACjB,CAAC,EArBW,QAAQ,KAAR,QAAQ,QAqBnB;AA8FD;;GAEG;AACH,MAAM,CAAN,IAAY,aA6BX;AA7BD,WAAY,aAAa;IACvB;;;OAGG;IACH,oCAAmB,CAAA;IACnB;;;;OAIG;IACH,gDAA+B,CAAA;IAC/B;;;OAGG;IACH,wDAAuC,CAAA;IACvC;;;;OAIG;IACH,8CAA6B,CAAA;IAC7B;;;;OAIG;IACH,8CAA6B,CAAA;AAC/B,CAAC,EA7BW,aAAa,KAAb,aAAa,QA6BxB"}
|