@iyio/aws-credential-providers 0.7.50 → 0.8.1

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.
Files changed (36) hide show
  1. package/package.json +12 -21
  2. package/src/index.d.ts +4 -4
  3. package/src/index.js +4 -7
  4. package/src/index.js.map +1 -1
  5. package/src/lib/CognitoAuthProvider.js +56 -60
  6. package/src/lib/CognitoAuthProvider.js.map +1 -1
  7. package/src/lib/CognitoJwtValidator.js +11 -15
  8. package/src/lib/CognitoJwtValidator.js.map +1 -1
  9. package/src/lib/_modules.aws-credential-providers.js +9 -14
  10. package/src/lib/_modules.aws-credential-providers.js.map +1 -1
  11. package/src/lib/_types.aws-credential-providers.js +8 -11
  12. package/src/lib/_types.aws-credential-providers.js.map +1 -1
  13. package/src/lib/cognito-test-helper.d.ts +1 -1
  14. package/src/lib/cognito-test-helper.js +12 -16
  15. package/src/lib/cognito-test-helper.js.map +1 -1
  16. package/src/package.json +1 -4
  17. package/tsconfig.tsbuildinfo +1 -0
  18. package/esm/package.json +0 -3
  19. package/esm/src/index.d.ts +0 -4
  20. package/esm/src/index.js +0 -5
  21. package/esm/src/index.js.map +0 -1
  22. package/esm/src/lib/CognitoAuthProvider.d.ts +0 -47
  23. package/esm/src/lib/CognitoAuthProvider.js +0 -504
  24. package/esm/src/lib/CognitoAuthProvider.js.map +0 -1
  25. package/esm/src/lib/CognitoJwtValidator.d.ts +0 -21
  26. package/esm/src/lib/CognitoJwtValidator.js +0 -56
  27. package/esm/src/lib/CognitoJwtValidator.js.map +0 -1
  28. package/esm/src/lib/_modules.aws-credential-providers.d.ts +0 -3
  29. package/esm/src/lib/_modules.aws-credential-providers.js +0 -12
  30. package/esm/src/lib/_modules.aws-credential-providers.js.map +0 -1
  31. package/esm/src/lib/_types.aws-credential-providers.d.ts +0 -12
  32. package/esm/src/lib/_types.aws-credential-providers.js +0 -14
  33. package/esm/src/lib/_types.aws-credential-providers.js.map +0 -1
  34. package/esm/src/lib/cognito-test-helper.d.ts +0 -3
  35. package/esm/src/lib/cognito-test-helper.js +0 -39
  36. package/esm/src/lib/cognito-test-helper.js.map +0 -1
@@ -1,56 +0,0 @@
1
- import { awsRegionParam } from '@iyio/aws';
2
- import { CognitoJwtVerifier } from "aws-jwt-verify";
3
- import { cognitoIdentityPoolIdParam, cognitoUserPoolClientIdParam, cognitoUserPoolIdParam } from './_types.aws-credential-providers';
4
- export const CognitoJwtValidatorType = 'CognitoJwtValidator';
5
- export class CognitoJwtValidator {
6
- static fromScope(scope) {
7
- return new CognitoJwtValidator({
8
- userPoolId: cognitoUserPoolIdParam(scope),
9
- clientId: cognitoUserPoolClientIdParam(scope),
10
- identityPoolId: cognitoIdentityPoolIdParam(scope),
11
- region: awsRegionParam(scope),
12
- });
13
- }
14
- constructor(config) {
15
- this.type = CognitoJwtValidatorType;
16
- this.verifierId = null;
17
- this.verifierAccess = null;
18
- this.config = config;
19
- }
20
- getIdVerifier() {
21
- return this.verifierId ?? (this.verifierId = this.createVerifier('id'));
22
- }
23
- getAccessVerifier() {
24
- return this.verifierId ?? (this.verifierId = this.createVerifier('access'));
25
- }
26
- createVerifier(tokenUse) {
27
- return CognitoJwtVerifier.create({
28
- userPoolId: this.config.userPoolId,
29
- clientId: this.config.clientId,
30
- tokenUse,
31
- });
32
- }
33
- async verifyAsync(jwt, tokenUse) {
34
- try {
35
- await (tokenUse === 'id' ? this.getIdVerifier() : this.getAccessVerifier()).verify(jwt);
36
- return true;
37
- }
38
- catch {
39
- return false;
40
- }
41
- }
42
- async validateJwtAsync(jwt, options) {
43
- const tokenUse = options?.['tokenUse'];
44
- if (tokenUse && (tokenUse !== 'id' && tokenUse !== 'access')) {
45
- return false;
46
- }
47
- if (tokenUse) {
48
- return await this.verifyAsync(jwt, tokenUse);
49
- }
50
- else {
51
- return ((await this.verifyAsync(jwt, 'access')) ||
52
- (await this.verifyAsync(jwt, 'id')));
53
- }
54
- }
55
- }
56
- //# sourceMappingURL=CognitoJwtValidator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CognitoJwtValidator.js","sourceRoot":"","sources":["../../../../../../packages/aws-credential-providers/src/lib/CognitoJwtValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,0BAA0B,EAAE,4BAA4B,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAWrI,MAAM,CAAC,MAAM,uBAAuB,GAAC,qBAAqB,CAAC;AAE3D,MAAM,OAAO,mBAAmB;IAErB,MAAM,CAAC,SAAS,CAAC,KAAW;QAC/B,OAAO,IAAI,mBAAmB,CAAC;YAC3B,UAAU,EAAC,sBAAsB,CAAC,KAAK,CAAC;YACxC,QAAQ,EAAC,4BAA4B,CAAC,KAAK,CAAC;YAC5C,cAAc,EAAC,0BAA0B,CAAC,KAAK,CAAC;YAChD,MAAM,EAAC,cAAc,CAAC,KAAK,CAAC;SAC/B,CAAC,CAAC;IACP,CAAC;IAMD,YAAY,MAAgC;QAJ5B,SAAI,GAAC,uBAAuB,CAAC;QASrC,eAAU,GAAsC,IAAI,CAAC;QACrD,mBAAc,GAAsC,IAAI,CAAC;QAJ7D,IAAI,CAAC,MAAM,GAAC,MAAM,CAAC;IACvB,CAAC;IAKO,aAAa;QACjB,OAAO,IAAI,CAAC,UAAU,IAAE,CAAC,IAAI,CAAC,UAAU,GAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAA;IACvE,CAAC;IAEO,iBAAiB;QACrB,OAAO,IAAI,CAAC,UAAU,IAAE,CAAC,IAAI,CAAC,UAAU,GAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAA;IAC3E,CAAC;IAEO,cAAc,CAAC,QAAsB;QACzC,OAAO,kBAAkB,CAAC,MAAM,CAAC;YAC7B,UAAU,EAAC,IAAI,CAAC,MAAM,CAAC,UAAU;YACjC,QAAQ,EAAC,IAAI,CAAC,MAAM,CAAC,QAAQ;YAC7B,QAAQ;SACX,CAAC,CAAC;IACP,CAAC;IAEO,KAAK,CAAC,WAAW,CAAC,GAAU,EAAC,QAAsB;QACvD,IAAG,CAAC;YACA,MAAM,CAAC,QAAQ,KAAG,IAAI,CAAA,CAAC,CAAA,IAAI,CAAC,aAAa,EAAE,CAAA,CAAC,CAAA,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAClF,OAAO,IAAI,CAAC;QAChB,CAAC;QAAA,MAAK,CAAC;YACH,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,gBAAgB,CAAC,GAAU,EAAC,OAA2B;QAEhE,MAAM,QAAQ,GAAe,OAAO,EAAE,CAAC,UAAU,CAAC,CAAC;QACnD,IAAG,QAAQ,IAAI,CAAC,QAAQ,KAAG,IAAI,IAAI,QAAQ,KAAG,QAAQ,CAAC,EAAC,CAAC;YACrD,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,IAAG,QAAQ,EAAC,CAAC;YACT,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,GAAG,EAAC,QAAQ,CAAC,CAAC;QAChD,CAAC;aAAI,CAAC;YACF,OAAO,CACH,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,GAAG,EAAC,QAAQ,CAAC,CAAC;gBACtC,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,GAAG,EAAC,IAAI,CAAC,CAAC,CACrC,CAAA;QACL,CAAC;IAEL,CAAC;CAEJ"}
@@ -1,3 +0,0 @@
1
- import { ScopeRegistration } from "@iyio/common";
2
- export declare const cognitoAuthProviderModule: (reg: ScopeRegistration) => void;
3
- export declare const cognitoBackendAuthProviderModule: (reg: ScopeRegistration) => void;
@@ -1,12 +0,0 @@
1
- import { AwsAuthProviders } from "@iyio/aws";
2
- import { AuthProviders, JwtValidators } from "@iyio/common";
3
- import { CognitoAuthProvider, CognitoAuthProviderType } from "./CognitoAuthProvider";
4
- import { CognitoJwtValidator, CognitoJwtValidatorType } from "./CognitoJwtValidator";
5
- export const cognitoAuthProviderModule = (reg) => {
6
- reg.addProvider(AuthProviders, scope => CognitoAuthProvider.fromScope(scope), CognitoAuthProviderType)
7
- .and(AwsAuthProviders);
8
- };
9
- export const cognitoBackendAuthProviderModule = (reg) => {
10
- reg.addProvider(JwtValidators, scope => CognitoJwtValidator.fromScope(scope), CognitoJwtValidatorType);
11
- };
12
- //# sourceMappingURL=_modules.aws-credential-providers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_modules.aws-credential-providers.js","sourceRoot":"","sources":["../../../../../../packages/aws-credential-providers/src/lib/_modules.aws-credential-providers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAqB,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAErF,MAAM,CAAC,MAAM,yBAAyB,GAAC,CAAC,GAAqB,EAAC,EAAE;IAC5D,GAAG,CAAC,WAAW,CAAC,aAAa,EAAC,KAAK,CAAA,EAAE,CAAA,mBAAmB,CAAC,SAAS,CAAC,KAAK,CAAC,EAAC,uBAAuB,CAAC;SAC7F,GAAG,CAAC,gBAAgB,CAAC,CAAC;AAC/B,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,gCAAgC,GAAC,CAAC,GAAqB,EAAC,EAAE;IACnE,GAAG,CAAC,WAAW,CAAC,aAAa,EAAC,KAAK,CAAA,EAAE,CAAA,mBAAmB,CAAC,SAAS,CAAC,KAAK,CAAC,EAAC,uBAAuB,CAAC,CAAA;AACtG,CAAC,CAAA"}
@@ -1,12 +0,0 @@
1
- export declare const cognitoIdentityPoolIdParam: import("@iyio/common").ParamTypeDef<string>;
2
- export declare const cognitoUserPoolClientIdParam: import("@iyio/common").ParamTypeDef<string>;
3
- export declare const cognitoUserPoolIdParam: import("@iyio/common").ParamTypeDef<string>;
4
- export declare const cognitoDomainPrefixParam: import("@iyio/common").ParamTypeDef<string>;
5
- export declare const disableCognitoUnauthenticatedParam: import("@iyio/common").ParamTypeDef<boolean>;
6
- /**
7
- * Redirect path to a page to handle an oauth code. Can be a full URL or a path. If is a path the
8
- * current host and protocol will be used.
9
- * @default '/oauth'
10
- */
11
- export declare const cognitoOAuthRedirectUriParam: import("@iyio/common").ParamTypeDef<string>;
12
- export declare const cognitoOAuthScopesParams: import("@iyio/common").ParamTypeDef<string>;
@@ -1,14 +0,0 @@
1
- import { defineBoolParam, defineStringParam } from "@iyio/common";
2
- export const cognitoIdentityPoolIdParam = defineStringParam('cognitoIdentityPoolId');
3
- export const cognitoUserPoolClientIdParam = defineStringParam('cognitoUserPoolClientId');
4
- export const cognitoUserPoolIdParam = defineStringParam('cognitoUserPoolId');
5
- export const cognitoDomainPrefixParam = defineStringParam('cognitoDomainPrefix');
6
- export const disableCognitoUnauthenticatedParam = defineBoolParam('disableCognitoUnauthenticated');
7
- /**
8
- * Redirect path to a page to handle an oauth code. Can be a full URL or a path. If is a path the
9
- * current host and protocol will be used.
10
- * @default '/oauth'
11
- */
12
- export const cognitoOAuthRedirectUriParam = defineStringParam('cognitoOAuthRedirectUri', '/oauth');
13
- export const cognitoOAuthScopesParams = defineStringParam('cognitoOAuthScopes', 'aws.cognito.signin.user.admin,email,openid,profile');
14
- //# sourceMappingURL=_types.aws-credential-providers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_types.aws-credential-providers.js","sourceRoot":"","sources":["../../../../../../packages/aws-credential-providers/src/lib/_types.aws-credential-providers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAElE,MAAM,CAAC,MAAM,0BAA0B,GAAC,iBAAiB,CAAC,uBAAuB,CAAC,CAAC;AACnF,MAAM,CAAC,MAAM,4BAA4B,GAAC,iBAAiB,CAAC,yBAAyB,CAAC,CAAC;AACvF,MAAM,CAAC,MAAM,sBAAsB,GAAC,iBAAiB,CAAC,mBAAmB,CAAC,CAAC;AAC3E,MAAM,CAAC,MAAM,wBAAwB,GAAC,iBAAiB,CAAC,qBAAqB,CAAC,CAAC;AAC/E,MAAM,CAAC,MAAM,kCAAkC,GAAC,eAAe,CAAC,+BAA+B,CAAC,CAAC;AACjG;;;;GAIG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAC,iBAAiB,CAAC,yBAAyB,EAAC,QAAQ,CAAC,CAAC;AAEhG,MAAM,CAAC,MAAM,wBAAwB,GAAC,iBAAiB,CAAC,oBAAoB,EAAC,oDAAoD,CAAC,CAAA"}
@@ -1,3 +0,0 @@
1
- import { BaseUser, Scope, ScopeModule } from "@iyio/common";
2
- import { CognitoAuthProviderConfig } from "./CognitoAuthProvider";
3
- export declare const useTempCognitoUser: (module: ScopeModule, work: (scope: Scope, user: BaseUser, config: CognitoAuthProviderConfig) => Promise<void>) => Promise<void>;
@@ -1,39 +0,0 @@
1
- import { AwsAuthProviders } from "@iyio/aws";
2
- import { AuthProviders, authService, createScope, MemoryStore, shortUuid, storeRoot, uuid } from "@iyio/common";
3
- import { CognitoAuthProvider } from "./CognitoAuthProvider";
4
- export const useTempCognitoUser = async (module, work) => {
5
- let provider = undefined;
6
- const scope = createScope(reg => {
7
- reg.use(module);
8
- provider = reg
9
- .addProvider(AuthProviders, scope => CognitoAuthProvider.fromScope(scope))
10
- .and(AwsAuthProviders)
11
- .getValue();
12
- });
13
- storeRoot(scope).mount('/', new MemoryStore());
14
- const email = `unit-test.${uuid()}@iyio.io`;
15
- const password = 'P1!p-' + shortUuid();
16
- console.log(`Registering ${email}, ${password}`);
17
- const result = await authService(scope).registerEmailPasswordAsync(email, password);
18
- if (result.status !== 'success') {
19
- console.log(result);
20
- throw new Error('Result not success');
21
- }
22
- try {
23
- await work(scope, result.user, provider.config);
24
- }
25
- finally {
26
- const deleteResult = await authService(scope).deleteAsync(result.user);
27
- if (deleteResult.status === 'error') {
28
- // eslint-disable-next-line no-unsafe-finally
29
- throw new Error('Failed to delete user');
30
- }
31
- else if (deleteResult.status === 'pending') {
32
- console.warn('Delete user pending');
33
- }
34
- else {
35
- console.log(`${email} deleted`);
36
- }
37
- }
38
- };
39
- //# sourceMappingURL=cognito-test-helper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cognito-test-helper.js","sourceRoot":"","sources":["../../../../../../packages/aws-credential-providers/src/lib/cognito-test-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAY,WAAW,EAAE,WAAW,EAAsB,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAC9I,OAAO,EAAE,mBAAmB,EAA6B,MAAM,uBAAuB,CAAC;AAEvF,MAAM,CAAC,MAAM,kBAAkB,GAAC,KAAK,EAAE,MAAkB,EAAC,IAAgF,EAAC,EAAE;IAEzI,IAAI,QAAQ,GAA+B,SAAS,CAAC;IAErD,MAAM,KAAK,GAAC,WAAW,CAAC,GAAG,CAAA,EAAE;QACzB,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAChB,QAAQ,GAAC,GAAG;aACP,WAAW,CAAC,aAAa,EAAC,KAAK,CAAA,EAAE,CAAA,mBAAmB,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;aACtE,GAAG,CAAC,gBAAgB,CAAC;aACrB,QAAQ,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,GAAG,EAAC,IAAI,WAAW,EAAE,CAAC,CAAC;IAE9C,MAAM,KAAK,GAAC,aAAa,IAAI,EAAE,UAAU,CAAC;IAC1C,MAAM,QAAQ,GAAC,OAAO,GAAC,SAAS,EAAE,CAAC;IAEnC,OAAO,CAAC,GAAG,CAAC,eAAe,KAAK,KAAK,QAAQ,EAAE,CAAC,CAAC;IAEjD,MAAM,MAAM,GAAC,MAAM,WAAW,CAAC,KAAK,CAAC,CAAC,0BAA0B,CAAC,KAAK,EAAC,QAAQ,CAAC,CAAC;IAEjF,IAAG,MAAM,CAAC,MAAM,KAAG,SAAS,EAAC,CAAC;QAC1B,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAC1C,CAAC;IAED,IAAG,CAAC;QAEA,MAAM,IAAI,CAAC,KAAK,EAAC,MAAM,CAAC,IAAI,EAAE,QAA2C,CAAC,MAAM,CAAC,CAAC;IAEtF,CAAC;YAAO,CAAC;QAEL,MAAM,YAAY,GAAC,MAAM,WAAW,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACrE,IAAG,YAAY,CAAC,MAAM,KAAG,OAAO,EAAC,CAAC;YAC9B,6CAA6C;YAC7C,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAC7C,CAAC;aAAK,IAAG,YAAY,CAAC,MAAM,KAAG,SAAS,EAAC,CAAC;YACtC,OAAO,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;QACxC,CAAC;aAAI,CAAC;YACF,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,UAAU,CAAC,CAAA;QACnC,CAAC;IACL,CAAC;AACL,CAAC,CAAA"}