@owlmeans/server-oidc-rp 0.1.0
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/LICENSE +21 -0
- package/README.md +520 -0
- package/build/.gitkeep +0 -0
- package/build/actions/index.d.ts +3 -0
- package/build/actions/index.d.ts.map +1 -0
- package/build/actions/index.js +3 -0
- package/build/actions/index.js.map +1 -0
- package/build/actions/init.d.ts +3 -0
- package/build/actions/init.d.ts.map +1 -0
- package/build/actions/init.js +68 -0
- package/build/actions/init.js.map +1 -0
- package/build/actions/process.d.ts +17 -0
- package/build/actions/process.d.ts.map +1 -0
- package/build/actions/process.js +80 -0
- package/build/actions/process.js.map +1 -0
- package/build/auth/consts.d.ts +2 -0
- package/build/auth/consts.d.ts.map +1 -0
- package/build/auth/consts.js +2 -0
- package/build/auth/consts.js.map +1 -0
- package/build/auth/index.d.ts +2 -0
- package/build/auth/index.d.ts.map +1 -0
- package/build/auth/index.js +2 -0
- package/build/auth/index.js.map +1 -0
- package/build/auth/plugins/index.d.ts +2 -0
- package/build/auth/plugins/index.d.ts.map +1 -0
- package/build/auth/plugins/index.js +6 -0
- package/build/auth/plugins/index.js.map +1 -0
- package/build/auth/plugins/oidc-client.d.ts +50 -0
- package/build/auth/plugins/oidc-client.d.ts.map +1 -0
- package/build/auth/plugins/oidc-client.js +211 -0
- package/build/auth/plugins/oidc-client.js.map +1 -0
- package/build/auth/plugins/types.d.ts +1 -0
- package/build/auth/plugins/types.d.ts.map +1 -0
- package/build/auth/plugins/types.js +2 -0
- package/build/auth/plugins/types.js.map +1 -0
- package/build/consts.d.ts +20 -0
- package/build/consts.d.ts.map +1 -0
- package/build/consts.js +20 -0
- package/build/consts.js.map +1 -0
- package/build/gate.d.ts +3 -0
- package/build/gate.d.ts.map +1 -0
- package/build/gate.js +22 -0
- package/build/gate.js.map +1 -0
- package/build/guard.d.ts +6 -0
- package/build/guard.d.ts.map +1 -0
- package/build/guard.js +13 -0
- package/build/guard.js.map +1 -0
- package/build/index.d.ts +8 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +7 -0
- package/build/index.js.map +1 -0
- package/build/model/consts.d.ts +6 -0
- package/build/model/consts.d.ts.map +1 -0
- package/build/model/consts.js +7 -0
- package/build/model/consts.js.map +1 -0
- package/build/model/gate.d.ts +4 -0
- package/build/model/gate.d.ts.map +1 -0
- package/build/model/gate.js +98 -0
- package/build/model/gate.js.map +1 -0
- package/build/model/types.d.ts +25 -0
- package/build/model/types.d.ts.map +1 -0
- package/build/model/types.js +2 -0
- package/build/model/types.js.map +1 -0
- package/build/models.d.ts +1 -0
- package/build/models.d.ts.map +1 -0
- package/build/models.js +2 -0
- package/build/models.js.map +1 -0
- package/build/modules.d.ts +3 -0
- package/build/modules.d.ts.map +1 -0
- package/build/modules.js +12 -0
- package/build/modules.js.map +1 -0
- package/build/service.d.ts +3 -0
- package/build/service.d.ts.map +1 -0
- package/build/service.js +186 -0
- package/build/service.js.map +1 -0
- package/build/types.d.ts +55 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/build/utils/auth.d.ts +5 -0
- package/build/utils/auth.d.ts.map +1 -0
- package/build/utils/auth.js +48 -0
- package/build/utils/auth.js.map +1 -0
- package/build/utils/cache.d.ts +8 -0
- package/build/utils/cache.d.ts.map +1 -0
- package/build/utils/cache.js +7 -0
- package/build/utils/cache.js.map +1 -0
- package/build/utils/index.d.ts +5 -0
- package/build/utils/index.d.ts.map +1 -0
- package/build/utils/index.js +4 -0
- package/build/utils/index.js.map +1 -0
- package/build/utils/types.d.ts +10 -0
- package/build/utils/types.d.ts.map +1 -0
- package/build/utils/types.js +2 -0
- package/build/utils/types.js.map +1 -0
- package/build/utils/wrapped.d.ts +4 -0
- package/build/utils/wrapped.d.ts.map +1 -0
- package/build/utils/wrapped.js +3 -0
- package/build/utils/wrapped.js.map +1 -0
- package/build/wrapper.d.ts +3 -0
- package/build/wrapper.d.ts.map +1 -0
- package/build/wrapper.js +75 -0
- package/build/wrapper.js.map +1 -0
- package/package.json +71 -0
- package/src/actions/index.ts +3 -0
- package/src/actions/init.ts +90 -0
- package/src/actions/process.ts +113 -0
- package/src/auth/consts.ts +2 -0
- package/src/auth/index.ts +2 -0
- package/src/auth/plugins/index.ts +8 -0
- package/src/auth/plugins/oidc-client.ts +246 -0
- package/src/auth/plugins/types.ts +0 -0
- package/src/consts.ts +26 -0
- package/src/gate.ts +29 -0
- package/src/guard.ts +25 -0
- package/src/index.ts +7 -0
- package/src/model/consts.ts +6 -0
- package/src/model/gate.ts +129 -0
- package/src/model/types.ts +31 -0
- package/src/models.ts +1 -0
- package/src/modules.ts +30 -0
- package/src/service.ts +251 -0
- package/src/types.ts +64 -0
- package/src/utils/auth.ts +67 -0
- package/src/utils/cache.ts +12 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/types.ts +10 -0
- package/src/utils/wrapped.ts +6 -0
- package/src/wrapper.ts +92 -0
- package/tsconfig.json +15 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { handleBody } from '@owlmeans/server-api';
|
|
2
|
+
import { OIDC_WRAPPED_TOKEN } from '@owlmeans/oidc';
|
|
3
|
+
import { assertContext } from '@owlmeans/context';
|
|
4
|
+
import Url from 'url';
|
|
5
|
+
import { makeOidcAuthentication } from '../utils/auth.js';
|
|
6
|
+
import { AuthenFailed, AuthManagerError, AuthRole } from '@owlmeans/auth';
|
|
7
|
+
import { decodeJwt } from 'jose';
|
|
8
|
+
import { cache, exchangeId, managedId } from '../utils/cache.js';
|
|
9
|
+
import { trust } from '@owlmeans/auth-common/utils';
|
|
10
|
+
import { TRUSTED } from '@owlmeans/config';
|
|
11
|
+
import { EnvelopeKind, makeEnvelopeModel } from '@owlmeans/basic-envelope';
|
|
12
|
+
import { OIDC_AUTH_LIFTETIME } from '../consts.js';
|
|
13
|
+
import { wrapper } from '../utils/wrapped.js';
|
|
14
|
+
/**
|
|
15
|
+
* Authentication method links together OIDC and OwlMeans auth.
|
|
16
|
+
* 1. We authenticate OIDC redirect back params with the classic OIDC client.
|
|
17
|
+
* 2. We temporary store on the server refresh token and OIDC token.
|
|
18
|
+
* 3. We supply the client with perked OwlMeans Auth token that in fact
|
|
19
|
+
* is the set of OIDC tokens (except refresh token - we keep it here?)
|
|
20
|
+
* 4. We used it in a centralized way to check permissions over OwlMeans Auth
|
|
21
|
+
* central service irrespectively is it OIDC or our custom permissions engine
|
|
22
|
+
* (this is useful to properly support paid accounts and bridge the underlying
|
|
23
|
+
* IAM system implemetation - abstract from it).
|
|
24
|
+
* 5. The method ends with production of OwlMeans authorization token.
|
|
25
|
+
*
|
|
26
|
+
* ! There is also token renewal mechanism that should be implemented nearby.
|
|
27
|
+
*/
|
|
28
|
+
export const authenticate = handleBody(async ({ authUrl, ...params }, ctx) => {
|
|
29
|
+
const context = assertContext(ctx);
|
|
30
|
+
const url = new Url.URL(authUrl);
|
|
31
|
+
const redirectUrl = url.searchParams.get('redirect_uri');
|
|
32
|
+
const [cfg, tokenSet, token] = await makeOidcAuthentication(context)({
|
|
33
|
+
challenge: redirectUrl + ':' + authUrl,
|
|
34
|
+
credential: new Url.URLSearchParams(params).toString()
|
|
35
|
+
});
|
|
36
|
+
console.log("\n\n ============ \n Config we got for real autentioncation", cfg);
|
|
37
|
+
if (tokenSet.id_token == null || tokenSet.access_token == null) {
|
|
38
|
+
throw new AuthenFailed();
|
|
39
|
+
}
|
|
40
|
+
if (cfg.service == null) {
|
|
41
|
+
throw new AuthManagerError('service');
|
|
42
|
+
}
|
|
43
|
+
await cache(context).delete(exchangeId(token));
|
|
44
|
+
console.log('List provided user permisssions', decodeJwt(tokenSet.access_token));
|
|
45
|
+
const id = decodeJwt(tokenSet.id_token);
|
|
46
|
+
console.log('token set', tokenSet, tokenSet.claims(), id);
|
|
47
|
+
let user = {
|
|
48
|
+
type: OIDC_WRAPPED_TOKEN,
|
|
49
|
+
token,
|
|
50
|
+
// @TODO Actually this is highly incorrect - we need to get profile details
|
|
51
|
+
// from the OwlMeans Auth intead ?
|
|
52
|
+
userId: id.sub,
|
|
53
|
+
// @TODO Actually we should check is it user or admin or even guest
|
|
54
|
+
// and set proper role
|
|
55
|
+
role: AuthRole.Guest,
|
|
56
|
+
// @TODO It's unclear if it's secure - but it's not used right now
|
|
57
|
+
scopes: [
|
|
58
|
+
...(context.cfg.shortAlias != null ? [context.cfg.shortAlias] : []),
|
|
59
|
+
...(context.cfg.alias != null ? [context.cfg.alias] : []),
|
|
60
|
+
context.cfg.service,
|
|
61
|
+
cfg.service,
|
|
62
|
+
],
|
|
63
|
+
source: `${cfg.service}/${cfg.clientId}${'id' in cfg ? `/${cfg.id}` : ''}`,
|
|
64
|
+
// @TODO Actually this is highly incorrect - we need to get profile details
|
|
65
|
+
// from the OwlMeans Auth intead
|
|
66
|
+
// profileId: user?.userId,
|
|
67
|
+
entityId: cfg.entityId,
|
|
68
|
+
isUser: true,
|
|
69
|
+
createdAt: new Date(),
|
|
70
|
+
};
|
|
71
|
+
console.log('>>>>> ~~~~~ STORE RECORD WITH ID: ', managedId(token));
|
|
72
|
+
await cache(context).create({ id: managedId(token), payload: tokenSet, client: cfg.clientId }, { ttl: OIDC_AUTH_LIFTETIME / 1000 });
|
|
73
|
+
const trusted = await trust(context, TRUSTED, context.cfg.alias ?? context.cfg.service);
|
|
74
|
+
const authorization = await makeEnvelopeModel(OIDC_WRAPPED_TOKEN)
|
|
75
|
+
.send(user, null).sign(trusted.key, EnvelopeKind.Token);
|
|
76
|
+
let auth = { token: `${OIDC_WRAPPED_TOKEN.toUpperCase()} ${authorization}` };
|
|
77
|
+
auth = await wrapper(context).update(auth, true) ?? auth;
|
|
78
|
+
return auth;
|
|
79
|
+
});
|
|
80
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/actions/process.ts"],"names":[],"mappings":"AACA,OA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C,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,CAAA;IAExD,OAAO,IAAI,CAAA;AACb,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../src/auth/consts.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,iBAAiB,cAAc,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../../src/auth/consts.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,iBAAiB,GAAG,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const plugins: Record<string, <C extends import("@owlmeans/server-auth/manager").AppConfig, T extends import("@owlmeans/server-auth/manager").AppContext<C>>(context: T) => import("@owlmeans/server-auth/manager/plugins").AuthPlugin>;
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/plugins/index.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,OAAO,0NAAc,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { plugins as authPlugins } from '@owlmeans/server-auth/manager';
|
|
2
|
+
import { oidcClientPlugin } from './oidc-client.js';
|
|
3
|
+
import { OIDC_CLIENT_AUTH } from '@owlmeans/oidc';
|
|
4
|
+
authPlugins[OIDC_CLIENT_AUTH] = oidcClientPlugin;
|
|
5
|
+
export const plugins = authPlugins;
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/auth/plugins/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAA;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEjD,WAAW,CAAC,gBAAgB,CAAC,GAAG,gBAAgE,CAAA;AAEhG,MAAM,CAAC,MAAM,OAAO,GAAG,WAAW,CAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { AuthPlugin } from '@owlmeans/server-auth/manager/plugins';
|
|
2
|
+
import type { Config, Context } from '../../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Actually the most of implementation desceibed here is a proprietary one and
|
|
5
|
+
* located within OwlMeans Auth service implmentation.
|
|
6
|
+
* We keep it here for easier code navigation and understanding of relying developers
|
|
7
|
+
* about what's going on but we can't show it.
|
|
8
|
+
*
|
|
9
|
+
* @See OwlMeans Auth {AccountLinkingService} interface implementation for more details
|
|
10
|
+
*
|
|
11
|
+
* We need to distinguish the following cases:
|
|
12
|
+
* 1. The user authenticates via owlmenas.org
|
|
13
|
+
* 1.1. The user authenticated in owlmeans.net via IAM product based account.
|
|
14
|
+
* 1.1.1. The user do it for the first time
|
|
15
|
+
* * We create an account
|
|
16
|
+
* * We create and link credentials from jwt to the account (i'm not sure if it's required)
|
|
17
|
+
* * We create the profile
|
|
18
|
+
* * We create and link credentials from jwt to the profile
|
|
19
|
+
* 1.1.2. The user do it not for the first time
|
|
20
|
+
* * We found the linked profile by jwt
|
|
21
|
+
* 1.2. The user autehnticated in owlmeans.net via OwlMeans ID
|
|
22
|
+
* 1.2.1. The user do it for the first time
|
|
23
|
+
* * Figure out if the user has OwlMeans ID linked to the authentication from jwt
|
|
24
|
+
* (GET /admin/realms/{realm}/users/{id}/federated-identity)
|
|
25
|
+
* * We create and link credentials from jwt to the profile
|
|
26
|
+
* 1.2.2. The user do it not for the first time
|
|
27
|
+
* * We found the linked profile by credentials from jwt
|
|
28
|
+
* 2. The user authenticates via a custom identity provider
|
|
29
|
+
* 2.1. The user auhtneticated in his identity provier directly
|
|
30
|
+
* 2.1.1. The user do it for the first time
|
|
31
|
+
* * We create a profile (we cant request info about his Owlmeans id)!
|
|
32
|
+
* * We create and link credentials from jwt to the profile
|
|
33
|
+
* * ! When the user will try to pay for something via this profile
|
|
34
|
+
* * we need to force him to link it to owlmeans.net profile / account.
|
|
35
|
+
* 2.1.2. The user do it not for the first time
|
|
36
|
+
* * We found the linked profile by jwt
|
|
37
|
+
* 2.2. The user authenticated in his identity provider via OwlMeans ID
|
|
38
|
+
* - This case actually shouldn't know anything about it until the profile is linked to the
|
|
39
|
+
* owlmeans.net acccount.
|
|
40
|
+
*
|
|
41
|
+
* Generailized
|
|
42
|
+
* 1. We try to get credentials
|
|
43
|
+
* 2. If there is no credentials we try to get more info abou the user
|
|
44
|
+
* 2.1. To do it we get admin client if it's presented for API access
|
|
45
|
+
* 2.2. If it's presented we get list of identity providers to figure out if there an owlmeans.net id
|
|
46
|
+
* 3. If there is no owlmeans.net account while the login is going through it - we create one
|
|
47
|
+
* 4. If there is no profile - we create one and link oidc credentials
|
|
48
|
+
*/
|
|
49
|
+
export declare const oidcClientPlugin: <C extends Config, T extends Context<C>>(context: T) => AuthPlugin;
|
|
50
|
+
//# sourceMappingURL=oidc-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oidc-client.d.ts","sourceRoot":"","sources":["../../../src/auth/plugins/oidc-client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAA;AACvE,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAqB,MAAM,gBAAgB,CAAA;AAgBxE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,KAAG,UAqLrF,CAAA"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { assertType } from '@owlmeans/server-auth/manager/plugins';
|
|
2
|
+
import { DEFAULT_ALIAS } from '../../consts.js';
|
|
3
|
+
import { OIDC_CLIENT_AUTH } from '@owlmeans/oidc';
|
|
4
|
+
import { base64urlnopad as base64 } from '@scure/base';
|
|
5
|
+
import { randomBytes } from '@noble/hashes/utils';
|
|
6
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
7
|
+
import { ALL_SCOPES, AuthenFailed, AuthenPayloadError, AuthManagerError, AuthRole } from '@owlmeans/auth';
|
|
8
|
+
import { AUTHEN_TIMEFRAME } from '@owlmeans/server-auth';
|
|
9
|
+
import { decodeJwt } from 'jose';
|
|
10
|
+
import { KEY_OWL } from '@owlmeans/did';
|
|
11
|
+
import { cache, verifierId } from '../../utils/cache.js';
|
|
12
|
+
import { makeOidcAuthentication } from '../../utils/auth.js';
|
|
13
|
+
// import { URL } from 'url'
|
|
14
|
+
/**
|
|
15
|
+
* Actually the most of implementation desceibed here is a proprietary one and
|
|
16
|
+
* located within OwlMeans Auth service implmentation.
|
|
17
|
+
* We keep it here for easier code navigation and understanding of relying developers
|
|
18
|
+
* about what's going on but we can't show it.
|
|
19
|
+
*
|
|
20
|
+
* @See OwlMeans Auth {AccountLinkingService} interface implementation for more details
|
|
21
|
+
*
|
|
22
|
+
* We need to distinguish the following cases:
|
|
23
|
+
* 1. The user authenticates via owlmenas.org
|
|
24
|
+
* 1.1. The user authenticated in owlmeans.net via IAM product based account.
|
|
25
|
+
* 1.1.1. The user do it for the first time
|
|
26
|
+
* * We create an account
|
|
27
|
+
* * We create and link credentials from jwt to the account (i'm not sure if it's required)
|
|
28
|
+
* * We create the profile
|
|
29
|
+
* * We create and link credentials from jwt to the profile
|
|
30
|
+
* 1.1.2. The user do it not for the first time
|
|
31
|
+
* * We found the linked profile by jwt
|
|
32
|
+
* 1.2. The user autehnticated in owlmeans.net via OwlMeans ID
|
|
33
|
+
* 1.2.1. The user do it for the first time
|
|
34
|
+
* * Figure out if the user has OwlMeans ID linked to the authentication from jwt
|
|
35
|
+
* (GET /admin/realms/{realm}/users/{id}/federated-identity)
|
|
36
|
+
* * We create and link credentials from jwt to the profile
|
|
37
|
+
* 1.2.2. The user do it not for the first time
|
|
38
|
+
* * We found the linked profile by credentials from jwt
|
|
39
|
+
* 2. The user authenticates via a custom identity provider
|
|
40
|
+
* 2.1. The user auhtneticated in his identity provier directly
|
|
41
|
+
* 2.1.1. The user do it for the first time
|
|
42
|
+
* * We create a profile (we cant request info about his Owlmeans id)!
|
|
43
|
+
* * We create and link credentials from jwt to the profile
|
|
44
|
+
* * ! When the user will try to pay for something via this profile
|
|
45
|
+
* * we need to force him to link it to owlmeans.net profile / account.
|
|
46
|
+
* 2.1.2. The user do it not for the first time
|
|
47
|
+
* * We found the linked profile by jwt
|
|
48
|
+
* 2.2. The user authenticated in his identity provider via OwlMeans ID
|
|
49
|
+
* - This case actually shouldn't know anything about it until the profile is linked to the
|
|
50
|
+
* owlmeans.net acccount.
|
|
51
|
+
*
|
|
52
|
+
* Generailized
|
|
53
|
+
* 1. We try to get credentials
|
|
54
|
+
* 2. If there is no credentials we try to get more info abou the user
|
|
55
|
+
* 2.1. To do it we get admin client if it's presented for API access
|
|
56
|
+
* 2.2. If it's presented we get list of identity providers to figure out if there an owlmeans.net id
|
|
57
|
+
* 3. If there is no owlmeans.net account while the login is going through it - we create one
|
|
58
|
+
* 4. If there is no profile - we create one and link oidc credentials
|
|
59
|
+
*/
|
|
60
|
+
export const oidcClientPlugin = (context) => {
|
|
61
|
+
const authenticate = makeOidcAuthentication(context);
|
|
62
|
+
const plugin = {
|
|
63
|
+
type: OIDC_CLIENT_AUTH,
|
|
64
|
+
init: async (request) => {
|
|
65
|
+
assertType(request.type, plugin);
|
|
66
|
+
if (context.cfg.oidc.restrictedProviders === false) {
|
|
67
|
+
throw new AuthManagerError('oidc.internal');
|
|
68
|
+
}
|
|
69
|
+
// @TODO Actually think about how to make oidc service configurable
|
|
70
|
+
const oidc = context.service(DEFAULT_ALIAS);
|
|
71
|
+
let entityId = request.entityId ?? oidc.getDefault();
|
|
72
|
+
if (entityId == null) {
|
|
73
|
+
throw new AuthenPayloadError('client');
|
|
74
|
+
}
|
|
75
|
+
if (context.cfg.oidc.restrictedProviders === true && oidc.getDefault() !== entityId) {
|
|
76
|
+
throw new AuthenPayloadError('client');
|
|
77
|
+
}
|
|
78
|
+
if (Array.isArray(context.cfg.oidc.restrictedProviders)
|
|
79
|
+
&& !context.cfg.oidc.restrictedProviders.includes(entityId)) {
|
|
80
|
+
throw new AuthenPayloadError('client');
|
|
81
|
+
}
|
|
82
|
+
const verifier = base64.encode(randomBytes(32));
|
|
83
|
+
const challenge = base64.encode(sha256(verifier));
|
|
84
|
+
console.log("\n\n We create verifierID (2): ", verifierId(challenge), verifier, " with client: ", entityId, "\n\n");
|
|
85
|
+
await cache(context).create({
|
|
86
|
+
id: verifierId(challenge),
|
|
87
|
+
verifier,
|
|
88
|
+
client: entityId
|
|
89
|
+
}, { ttl: AUTHEN_TIMEFRAME / 1000 });
|
|
90
|
+
if (request.source == null) {
|
|
91
|
+
throw new AuthenPayloadError('redirect-uri');
|
|
92
|
+
}
|
|
93
|
+
// const redirectUrl = new URL(request.source)
|
|
94
|
+
// for (let key of redirectUrl.searchParams.keys()) {
|
|
95
|
+
// redirectUrl.searchParams.delete(key)
|
|
96
|
+
// }
|
|
97
|
+
const client = await oidc.getClient(entityId);
|
|
98
|
+
const cfg = client.getConfig();
|
|
99
|
+
const url = client.makeAuthUrl({
|
|
100
|
+
scope: `openid profile email ${cfg?.extraScopes ?? ''}`,
|
|
101
|
+
code_challenge: challenge,
|
|
102
|
+
code_challenge_method: 'S256',
|
|
103
|
+
redirect_uri: request.source,
|
|
104
|
+
});
|
|
105
|
+
return { challenge: url };
|
|
106
|
+
},
|
|
107
|
+
authenticate: async (credential) => {
|
|
108
|
+
console.log('000000000000000');
|
|
109
|
+
const [cfg, tokenSet, exchangeToken] = await authenticate(credential);
|
|
110
|
+
if (tokenSet.id_token == null || tokenSet.access_token == null) {
|
|
111
|
+
throw new AuthenFailed();
|
|
112
|
+
}
|
|
113
|
+
const oidc = context.service(DEFAULT_ALIAS);
|
|
114
|
+
const jwt = decodeJwt(tokenSet.id_token);
|
|
115
|
+
if (jwt.sub == null) {
|
|
116
|
+
throw new AuthenFailed();
|
|
117
|
+
}
|
|
118
|
+
const store = oidc.accountLinking();
|
|
119
|
+
if (store == null) {
|
|
120
|
+
throw new AuthManagerError('oidc.account.store');
|
|
121
|
+
}
|
|
122
|
+
if (cfg.service == null) {
|
|
123
|
+
throw new AuthManagerError('oidc.service');
|
|
124
|
+
}
|
|
125
|
+
let profile = await store.getLinkedProfile({
|
|
126
|
+
type: OIDC_CLIENT_AUTH,
|
|
127
|
+
service: cfg.service,
|
|
128
|
+
clientId: cfg.clientId,
|
|
129
|
+
userId: jwt.sub
|
|
130
|
+
});
|
|
131
|
+
// @TODO It's likely the case when we are talking about owlmeans.net
|
|
132
|
+
// but some addtional checks need to be done.
|
|
133
|
+
// The problem is that we will make the sold identity providers also
|
|
134
|
+
// managable, so this condition isn't enough to cover described cases.
|
|
135
|
+
let details;
|
|
136
|
+
if (cfg.apiClientId != null) {
|
|
137
|
+
console.log(1);
|
|
138
|
+
const apiClient = await oidc.getClient(cfg.apiClientId);
|
|
139
|
+
const adminTokens = await apiClient.grantWithCredentials();
|
|
140
|
+
if (adminTokens.access_token == null) {
|
|
141
|
+
throw new AuthManagerError('iam.admin');
|
|
142
|
+
}
|
|
143
|
+
const api = oidc.providerApi();
|
|
144
|
+
if (api == null) {
|
|
145
|
+
// @TODO And what if don't? Probably we can still do something here
|
|
146
|
+
throw new AuthManagerError('iam.admin.api');
|
|
147
|
+
}
|
|
148
|
+
details = await api.getUserDetails(adminTokens.access_token, jwt.sub);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
// @TODO We need to do something here if it's an external identity provider
|
|
152
|
+
// and we couldn't get any addiontal info
|
|
153
|
+
throw new AuthManagerError('implemented');
|
|
154
|
+
}
|
|
155
|
+
if (
|
|
156
|
+
// Create profile
|
|
157
|
+
profile == null
|
|
158
|
+
// Fix profile if it's not linked properly to OwlMeans Id
|
|
159
|
+
|| (details.did != null && details.isOwlMeansId && !profile.profileId?.startsWith(KEY_OWL + ':'))) {
|
|
160
|
+
console.log(2);
|
|
161
|
+
details.isOwlMeansId ??= cfg.entityId != null && cfg.entityId === context.cfg.defaultEntityId;
|
|
162
|
+
if (details.isOwlMeansId && context.cfg.defaultEntityId == null) {
|
|
163
|
+
throw new AuthManagerError('iam.governance');
|
|
164
|
+
}
|
|
165
|
+
details.entityId = details.isOwlMeansId ? context.cfg.defaultEntityId : cfg.entityId;
|
|
166
|
+
if (details.entityId == null) {
|
|
167
|
+
// @TODO We doesn't support clients and entites that aren't bound to an organization
|
|
168
|
+
// right now. Probably we should. Probably there are some cases when we have to.
|
|
169
|
+
throw new AuthManagerError('iam.entity');
|
|
170
|
+
}
|
|
171
|
+
console.log('Supper attention ~%~: ', details.entityId, cfg.entityId, context.cfg.defaultEntityId);
|
|
172
|
+
// We relink existing profile only if it's not yet did bound
|
|
173
|
+
// and the orgnaization is owlmeans.net
|
|
174
|
+
if (profile == null || (details.entityId === context.cfg.defaultEntityId
|
|
175
|
+
// @TODO Figure out more flexible solution.
|
|
176
|
+
// This check prevent a potenatilly vulnarability when a user can
|
|
177
|
+
// connect its own idp to his arbitrary IAM system that is connected as
|
|
178
|
+
// idp to our IAM system, and create an internal idp link that
|
|
179
|
+
// uses owlmeans did as user id of another user to link an arbitrary
|
|
180
|
+
// profile to his or her owlmeans user account and take adavantage of cross login.
|
|
181
|
+
// Probably such cross login accross owner like profiles should be prevented
|
|
182
|
+
// without additional authentication. But for now, this check guaranty that it works
|
|
183
|
+
// only with owlmeans.net idp that is managed by ours.
|
|
184
|
+
&& details.entityId === cfg.entityId)) {
|
|
185
|
+
console.log(3, details);
|
|
186
|
+
profile = await store.linkProfile({
|
|
187
|
+
...details,
|
|
188
|
+
service: cfg.service,
|
|
189
|
+
clientId: cfg.clientId,
|
|
190
|
+
type: OIDC_CLIENT_AUTH,
|
|
191
|
+
}, {
|
|
192
|
+
username: jwt.preferred_username ?? details.username,
|
|
193
|
+
// @TODO It's important to keep it this way to make registration disabling working
|
|
194
|
+
force: false
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
console.log(4);
|
|
199
|
+
credential.scopes = [ALL_SCOPES];
|
|
200
|
+
credential.source = cfg.clientId;
|
|
201
|
+
credential.role = AuthRole.User;
|
|
202
|
+
credential.type = OIDC_CLIENT_AUTH;
|
|
203
|
+
credential.userId = profile.userId;
|
|
204
|
+
credential.profileId = profile.profileId;
|
|
205
|
+
credential.entityId = profile.entityId;
|
|
206
|
+
return { token: exchangeToken };
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
return plugin;
|
|
210
|
+
};
|
|
211
|
+
//# sourceMappingURL=oidc-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oidc-client.js","sourceRoot":"","sources":["../../../src/auth/plugins/oidc-client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAA;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEjD,OAAO,EAAE,cAAc,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA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,GAAG,CAAC,QAAQ;wBACtB,IAAI,EAAE,gBAAgB;qBACvB,EAAE;wBACD,QAAQ,EAAE,GAAG,CAAC,kBAA4B,IAAI,OAAO,CAAC,QAAQ;wBAC9D,kFAAkF;wBAClF,KAAK,EAAE,KAAK;qBACb,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;YAEd,UAAU,CAAC,MAAM,GAAG,CAAC,UAAU,CAAC,CAAA;YAChC,UAAU,CAAC,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAA;YAChC,UAAU,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAA;YAC/B,UAAU,CAAC,IAAI,GAAG,gBAAgB,CAAA;YAClC,UAAU,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;YAClC,UAAU,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;YACxC,UAAU,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;YAEtC,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,CAAA;QACjC,CAAC;KACF,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/auth/plugins/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/auth/plugins/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const DEFAULT_ALIAS = "oidc-client";
|
|
2
|
+
export declare const DEF_OIDC_ACCOUNT_LINKING = "oidc-consumer-account-linking";
|
|
3
|
+
export declare const DEF_OIDC_PROVIDER_API = "oidc-consumer-provider-api";
|
|
4
|
+
export declare const authService: {
|
|
5
|
+
provider: {
|
|
6
|
+
list: string;
|
|
7
|
+
};
|
|
8
|
+
auth: {
|
|
9
|
+
update: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare const OIDC_TOKEN_STORE = "oidc-token-store";
|
|
13
|
+
/**
|
|
14
|
+
* @TODO Actually these ones should be constants and should be linked to
|
|
15
|
+
* configuration on OIDC provider side
|
|
16
|
+
*/
|
|
17
|
+
export declare const PROVIDER_CACHE_TTL: number;
|
|
18
|
+
export declare const OIDC_AUTH_LIFTETIME: number;
|
|
19
|
+
export declare const OIDC_WRAP_FRESHNESS: number;
|
|
20
|
+
//# sourceMappingURL=consts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa,gBAAgB,CAAA;AAE1C,eAAO,MAAM,wBAAwB,kCAAkC,CAAA;AAEvE,eAAO,MAAM,qBAAqB,+BAA+B,CAAA;AAEjE,eAAO,MAAM,WAAW;;;;;;;CAOvB,CAAA;AAED,eAAO,MAAM,gBAAgB,qBAAqB,CAAA;AAClD;;;GAGG;AACH,eAAO,MAAM,kBAAkB,QAAsB,CAAA;AAErD,eAAO,MAAM,mBAAmB,QAAmB,CAAA;AAEnD,eAAO,MAAM,mBAAmB,QAAsB,CAAA"}
|
package/build/consts.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const DEFAULT_ALIAS = 'oidc-client';
|
|
2
|
+
export const DEF_OIDC_ACCOUNT_LINKING = 'oidc-consumer-account-linking';
|
|
3
|
+
export const DEF_OIDC_PROVIDER_API = 'oidc-consumer-provider-api';
|
|
4
|
+
export const authService = {
|
|
5
|
+
provider: {
|
|
6
|
+
list: 'external-auth:provider:list'
|
|
7
|
+
},
|
|
8
|
+
auth: {
|
|
9
|
+
update: 'external-auth:auth:update'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
export const OIDC_TOKEN_STORE = 'oidc-token-store';
|
|
13
|
+
/**
|
|
14
|
+
* @TODO Actually these ones should be constants and should be linked to
|
|
15
|
+
* configuration on OIDC provider side
|
|
16
|
+
*/
|
|
17
|
+
export const PROVIDER_CACHE_TTL = (5 * 60 - 1) * 1000;
|
|
18
|
+
export const OIDC_AUTH_LIFTETIME = 24 * 3600 * 1000;
|
|
19
|
+
export const OIDC_WRAP_FRESHNESS = (5 * 60 - 1) * 1000;
|
|
20
|
+
//# sourceMappingURL=consts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAA;AAE1C,MAAM,CAAC,MAAM,wBAAwB,GAAG,+BAA+B,CAAA;AAEvE,MAAM,CAAC,MAAM,qBAAqB,GAAG,4BAA4B,CAAA;AAEjE,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,QAAQ,EAAE;QACR,IAAI,EAAE,6BAA6B;KACpC;IACD,IAAI,EAAE;QACJ,MAAM,EAAE,2BAA2B;KACpC;CACF,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAA;AAClD;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAA;AAErD,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAA;AAEnD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAA"}
|
package/build/gate.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../src/gate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAMnD,eAAO,MAAM,YAAY,WAAW,MAAM,KAAe,WAqBxD,CAAA"}
|
package/build/gate.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createLazyService } from '@owlmeans/context';
|
|
2
|
+
import { OIDC_GATE } from '@owlmeans/oidc';
|
|
3
|
+
import { AuthForbidden } from '@owlmeans/auth';
|
|
4
|
+
import { createGateModel } from './model/gate.js';
|
|
5
|
+
export const makeOidcGate = (alias = OIDC_GATE) => {
|
|
6
|
+
const service = createLazyService(alias, {
|
|
7
|
+
assert: async (req, _, params) => {
|
|
8
|
+
await service.ready();
|
|
9
|
+
const ctx = service.assertCtx();
|
|
10
|
+
if (req.auth == null) {
|
|
11
|
+
throw new AuthForbidden('auth');
|
|
12
|
+
}
|
|
13
|
+
const model = createGateModel(ctx);
|
|
14
|
+
const permissions = await model.loadPermissions(req.auth, params);
|
|
15
|
+
if (permissions.length < 1) {
|
|
16
|
+
throw new AuthForbidden('permission');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return service;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=gate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gate.js","sourceRoot":"","sources":["../src/gate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,QAAgB,SAAS,EAAe,EAAE;IACrE,MAAM,OAAO,GAAgB,iBAAiB,CAAc,KAAK,EAAE;QACjE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE;YAC/B,MAAM,OAAO,CAAC,KAAK,EAAE,CAAA;YACrB,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,EAAmB,CAAA;YAEhD,IAAI,GAAG,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;gBACrB,MAAM,IAAI,aAAa,CAAC,MAAM,CAAC,CAAA;YACjC,CAAC;YAED,MAAM,KAAK,GAAG,eAAe,CAAC,GAAG,CAAC,CAAA;YAElC,MAAM,WAAW,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;YAEjE,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC3B,MAAM,IAAI,aAAa,CAAC,YAAY,CAAC,CAAA;YACvC,CAAC;QACH,CAAC;KACF,CAAC,CAAA;IAEF,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
|
package/build/guard.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { OidcGuardOptions } from '@owlmeans/oidc';
|
|
2
|
+
import type { Config, Context } from './types.js';
|
|
3
|
+
import type { CommonModule } from '@owlmeans/module';
|
|
4
|
+
export declare const appendOidcGuard: <C extends Config, T extends Context<C>>(context: T, opts?: OidcGuardOptions) => T;
|
|
5
|
+
export declare const setupOidcGuard: (modules: CommonModule[], coguards?: string | string[]) => void;
|
|
6
|
+
//# sourceMappingURL=guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../src/guard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AASpD,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,WAC3D,CAAC,SAAS,gBAAgB,MAKpC,CAAA;AAED,eAAO,MAAM,cAAc,YAAa,YAAY,EAAE,aAAa,MAAM,GAAG,MAAM,EAAE,SAKnF,CAAA"}
|
package/build/guard.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { appendOidcGuard as appendBasicOidcGuard, setupOidcGuard as setupBasicOidcGuard, DISPATCHER_OIDC, DISPATCHER_OIDC_INIT } from '@owlmeans/oidc';
|
|
2
|
+
import { elevate } from '@owlmeans/server-module';
|
|
3
|
+
import * as actions from './actions/index.js';
|
|
4
|
+
export const appendOidcGuard = (context, opts) => {
|
|
5
|
+
const ctx = appendBasicOidcGuard(context, opts);
|
|
6
|
+
return ctx;
|
|
7
|
+
};
|
|
8
|
+
export const setupOidcGuard = (modules, coguards) => {
|
|
9
|
+
setupBasicOidcGuard(modules, coguards);
|
|
10
|
+
elevate(modules, DISPATCHER_OIDC_INIT, actions.init);
|
|
11
|
+
elevate(modules, DISPATCHER_OIDC, actions.authenticate);
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../src/guard.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,eAAe,IAAI,oBAAoB,EACvC,cAAc,IAAI,mBAAmB,EACrC,eAAe,EAAE,oBAAoB,EACtC,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AACjD,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAE7C,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,OAAU,EAAE,IAAuB,EACnC,EAAE;IACF,MAAM,GAAG,GAAG,oBAAoB,CAAO,OAAO,EAAE,IAAI,CAAC,CAAA;IAErD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAuB,EAAE,QAA4B,EAAE,EAAE;IACtF,mBAAmB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;IAEtC,OAAO,CAAC,OAAO,EAAE,oBAAoB,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IACpD,OAAO,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,CAAC,YAAY,CAAC,CAAA;AACzD,CAAC,CAAA"}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../src/model/consts.ts"],"names":[],"mappings":"AACA,oBAAY,YAAY;IACtB,WAAW,gBAAgB;IAC3B,KAAK,UAAU;IACf,QAAQ,aAAa;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../../src/model/consts.ts"],"names":[],"mappings":"AACA,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,2CAA2B,CAAA;IAC3B,+BAAe,CAAA;IACf,qCAAqB,CAAA;AACvB,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../../src/model/gate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAqB,MAAM,aAAa,CAAA;AAErE,OAAO,KAAK,EAAE,SAAS,EAAyC,MAAM,YAAY,CAAA;AAKlF,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAG,SAuHhF,CAAA"}
|