@lafken/auth 0.10.5 → 0.11.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/lib/resolver/auth/auth.d.ts +2 -0
- package/lib/resolver/auth/auth.js +25 -18
- package/lib/resolver/auth/user-pool/external/external.js +4 -2
- package/lib/resolver/auth/user-pool/internal/internal.js +2 -2
- package/lib/resolver/auth/user-pool/user-pool.types.d.ts +3 -2
- package/lib/resolver/auth/user-pool-client/external/external.d.ts +2 -2
- package/lib/resolver/auth/user-pool-client/external/external.js +7 -3
- package/lib/resolver/auth/user-pool-client/internal/internal.d.ts +2 -2
- package/lib/resolver/auth/user-pool-client/internal/internal.js +5 -4
- package/lib/resolver/auth/user-pool-client/user-pool-client.types.d.ts +10 -2
- package/lib/resolver/auth/user-pool-client/user-pool-client.utils.d.ts +21 -0
- package/lib/resolver/auth/user-pool-client/user-pool-client.utils.js +12 -0
- package/lib/resolver/resolver.types.d.ts +1 -1
- package/package.json +4 -4
|
@@ -17,34 +17,41 @@ class Auth extends constructs_1.Construct {
|
|
|
17
17
|
this.props = props;
|
|
18
18
|
}
|
|
19
19
|
async create() {
|
|
20
|
+
this.createUserPool();
|
|
21
|
+
this.createUserPoolClient();
|
|
22
|
+
}
|
|
23
|
+
async callExtends() {
|
|
24
|
+
if (this.props.extend) {
|
|
25
|
+
await this.props.extend({
|
|
26
|
+
scope: this,
|
|
27
|
+
userPool: this.userPool,
|
|
28
|
+
userPoolClient: this.userPoolClient?.cognitoUserPoolClient,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
createUserPool() {
|
|
20
33
|
if (this.props.userPool?.isExternal) {
|
|
21
34
|
this.userPool = new external_1.ExternalUserPool(this, this.id, this.props.userPool);
|
|
35
|
+
return;
|
|
22
36
|
}
|
|
23
|
-
|
|
24
|
-
|
|
37
|
+
this.userPool = new internal_1.InternalUserPool(this, this.id, this.props.userPool || {});
|
|
38
|
+
}
|
|
39
|
+
createUserPoolClient() {
|
|
40
|
+
if (!this.props.userClient) {
|
|
41
|
+
return;
|
|
25
42
|
}
|
|
26
43
|
if (this.props.userClient?.isExternal) {
|
|
27
44
|
this.userPoolClient = new external_2.ExternalUserPoolClient(this, this.id, {
|
|
28
45
|
userPoolId: this.userPool.id,
|
|
29
46
|
...this.props.userClient,
|
|
30
47
|
});
|
|
48
|
+
return;
|
|
31
49
|
}
|
|
32
|
-
|
|
33
|
-
this.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
async callExtends() {
|
|
41
|
-
if (this.props.extend) {
|
|
42
|
-
await this.props.extend({
|
|
43
|
-
scope: this,
|
|
44
|
-
userPool: this.userPool,
|
|
45
|
-
userPoolClient: this.userPoolClient.cognitoUserPoolClient,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
50
|
+
this.userPoolClient = new internal_2.InternalUserPoolClient(this, this.id, {
|
|
51
|
+
userPoolId: this.userPool.id,
|
|
52
|
+
...this.props.userClient,
|
|
53
|
+
attributeByName: this.userPool instanceof internal_1.InternalUserPool ? this.userPool?.attributeByName : {},
|
|
54
|
+
});
|
|
48
55
|
}
|
|
49
56
|
}
|
|
50
57
|
exports.Auth = Auth;
|
|
@@ -6,9 +6,11 @@ const resolver_1 = require("@lafken/resolver");
|
|
|
6
6
|
class ExternalUserPool extends resolver_1.lafkenResource.make(data_aws_cognito_user_pool_1.DataAwsCognitoUserPool) {
|
|
7
7
|
constructor(scope, id, props) {
|
|
8
8
|
super(scope, `${id}-user-pool`, {
|
|
9
|
-
userPoolId: props.userPoolId
|
|
9
|
+
userPoolId: typeof props.userPoolId === 'string'
|
|
10
|
+
? props.userPoolId
|
|
11
|
+
: props.userPoolId((0, resolver_1.getExternalValues)(scope)),
|
|
10
12
|
});
|
|
11
|
-
this.isGlobal('
|
|
13
|
+
this.isGlobal('user-pool', id);
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
exports.ExternalUserPool = ExternalUserPool;
|
|
@@ -18,7 +18,7 @@ class InternalUserPool extends resolver_1.lafkenResource.make(cognito_user_pool_
|
|
|
18
18
|
const attributes = InternalUserPool.getUserAttributes(props.attributes);
|
|
19
19
|
super(scope, `${id}-user-pool`, {
|
|
20
20
|
...InternalUserPool.getMfaConfig(props.mfa),
|
|
21
|
-
name: id,
|
|
21
|
+
name: props.name || id,
|
|
22
22
|
autoVerifiedAttributes: InternalUserPool.getAutoVerifiedAttributes(props.autoVerifyAttributes),
|
|
23
23
|
accountRecoverySetting: InternalUserPool.getAccountRecoverySettings(props.accountRecovery),
|
|
24
24
|
aliasAttributes: InternalUserPool.getAliasAttributes(props.signInAliases),
|
|
@@ -39,7 +39,7 @@ class InternalUserPool extends resolver_1.lafkenResource.make(cognito_user_pool_
|
|
|
39
39
|
if (attributes?.attributeByName) {
|
|
40
40
|
this.attributeByName = attributes.attributeByName;
|
|
41
41
|
}
|
|
42
|
-
this.isGlobal('
|
|
42
|
+
this.isGlobal('user-pool', id);
|
|
43
43
|
this.assignIdentityProviders(props.identityProviders);
|
|
44
44
|
new resolver_1.ResourceOutput(this, props.outputs);
|
|
45
45
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ClassResource, ResourceOutputType } from '@lafken/common';
|
|
1
|
+
import type { ClassResource, GetExternalValues, ResourceOutputType } from '@lafken/common';
|
|
2
2
|
export type SignInAliases = 'email' | 'phone' | 'preferred_username';
|
|
3
3
|
export type CognitoPlan = 'lite' | 'essentials' | 'plus';
|
|
4
4
|
export type UserVerificationType = 'code' | 'link';
|
|
@@ -102,6 +102,7 @@ export interface OidcIdentityProvider<T extends Function> extends CommonIdentity
|
|
|
102
102
|
}
|
|
103
103
|
export type IdentityProvider<T extends ClassResource> = AmazonIdentityProvider<T> | AppleIdentityProvider<T> | FacebookIdentityProvider<T> | GoogleIdentityProvider<T> | OidcIdentityProvider<T>;
|
|
104
104
|
export interface InternalUserPoolProps<T extends ClassResource> {
|
|
105
|
+
name?: string;
|
|
105
106
|
isExternal?: never;
|
|
106
107
|
/**
|
|
107
108
|
* Defines the attributes for the Cognito User Pool.
|
|
@@ -258,6 +259,6 @@ export interface ExternalUserPoolProps {
|
|
|
258
259
|
* This value is used to look up and integrate with a User Pool
|
|
259
260
|
* that was created outside of the framework.
|
|
260
261
|
*/
|
|
261
|
-
userPoolId: string;
|
|
262
|
+
userPoolId: string | ((props: GetExternalValues) => string);
|
|
262
263
|
}
|
|
263
264
|
export type UserPoolProps<T extends ClassResource> = InternalUserPoolProps<T> | ExternalUserPoolProps;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DataAwsCognitoUserPoolClient } from '@cdktn/provider-aws/lib/data-aws-cognito-user-pool-client';
|
|
2
1
|
import { Construct } from 'constructs';
|
|
3
2
|
import type { ExternalUserPoolClientProps } from '../user-pool-client.types';
|
|
3
|
+
import { DataExternalUserPoolClient } from '../user-pool-client.utils';
|
|
4
4
|
export declare class ExternalUserPoolClient extends Construct {
|
|
5
|
-
cognitoUserPoolClient:
|
|
5
|
+
cognitoUserPoolClient: DataExternalUserPoolClient;
|
|
6
6
|
constructor(scope: Construct, id: string, props: ExternalUserPoolClientProps);
|
|
7
7
|
}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExternalUserPoolClient = void 0;
|
|
4
|
-
const
|
|
4
|
+
const resolver_1 = require("@lafken/resolver");
|
|
5
5
|
const constructs_1 = require("constructs");
|
|
6
|
+
const user_pool_client_utils_1 = require("../user-pool-client.utils");
|
|
6
7
|
class ExternalUserPoolClient extends constructs_1.Construct {
|
|
7
8
|
cognitoUserPoolClient;
|
|
8
9
|
constructor(scope, id, props) {
|
|
9
10
|
super(scope, 'user-pool-client');
|
|
10
|
-
this.cognitoUserPoolClient = new
|
|
11
|
-
clientId: props.clientId
|
|
11
|
+
this.cognitoUserPoolClient = new user_pool_client_utils_1.DataExternalUserPoolClient(this, id, {
|
|
12
|
+
clientId: typeof props.clientId === 'string'
|
|
13
|
+
? props.clientId
|
|
14
|
+
: props.clientId((0, resolver_1.getExternalValues)(scope)),
|
|
12
15
|
userPoolId: props.userPoolId,
|
|
13
16
|
});
|
|
17
|
+
this.cognitoUserPoolClient.isGlobal('user-pool-client', id);
|
|
14
18
|
}
|
|
15
19
|
}
|
|
16
20
|
exports.ExternalUserPoolClient = ExternalUserPoolClient;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { CognitoUserPoolClient } from '@cdktn/provider-aws/lib/cognito-user-pool-client';
|
|
2
1
|
import { Construct } from 'constructs';
|
|
3
2
|
import type { InternalUserPoolClientProps } from '../user-pool-client.types';
|
|
3
|
+
import { DataInternalUserPoolClient } from '../user-pool-client.utils';
|
|
4
4
|
export declare class InternalUserPoolClient extends Construct {
|
|
5
5
|
private props;
|
|
6
|
-
cognitoUserPoolClient:
|
|
6
|
+
cognitoUserPoolClient: DataInternalUserPoolClient;
|
|
7
7
|
constructor(scope: Construct, id: string, props: InternalUserPoolClientProps);
|
|
8
8
|
private getRefreshTokenRotation;
|
|
9
9
|
private getExplicitAuthFlows;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InternalUserPoolClient = void 0;
|
|
4
|
-
const cognito_user_pool_client_1 = require("@cdktn/provider-aws/lib/cognito-user-pool-client");
|
|
5
4
|
const resolver_1 = require("@lafken/resolver");
|
|
6
5
|
const constructs_1 = require("constructs");
|
|
7
6
|
const auth_utils_1 = require("../../auth.utils");
|
|
7
|
+
const user_pool_client_utils_1 = require("../user-pool-client.utils");
|
|
8
8
|
class InternalUserPoolClient extends constructs_1.Construct {
|
|
9
9
|
props;
|
|
10
10
|
cognitoUserPoolClient;
|
|
11
11
|
constructor(scope, id, props) {
|
|
12
12
|
super(scope, 'user-pool-client');
|
|
13
13
|
this.props = props;
|
|
14
|
-
this.cognitoUserPoolClient = new
|
|
14
|
+
this.cognitoUserPoolClient = new user_pool_client_utils_1.DataInternalUserPoolClient(this, id, {
|
|
15
15
|
...this.getValidity(props),
|
|
16
16
|
...this.getOauthConfig(props.oauth),
|
|
17
|
-
name: id,
|
|
17
|
+
name: props.name || id,
|
|
18
18
|
userPoolId: props.userPoolId,
|
|
19
19
|
enableTokenRevocation: props.enableTokenRevocation ?? true,
|
|
20
20
|
generateSecret: props.generateSecret ?? false,
|
|
@@ -24,6 +24,7 @@ class InternalUserPoolClient extends constructs_1.Construct {
|
|
|
24
24
|
readAttributes: this.getAttributes(props.readAttributes),
|
|
25
25
|
writeAttributes: this.getAttributes(props.writeAttributes),
|
|
26
26
|
});
|
|
27
|
+
this.cognitoUserPoolClient.isGlobal('user-pool-client', id);
|
|
27
28
|
new resolver_1.ResourceOutput(this.cognitoUserPoolClient, props.outputs);
|
|
28
29
|
}
|
|
29
30
|
getRefreshTokenRotation(period) {
|
|
@@ -44,7 +45,7 @@ class InternalUserPoolClient extends constructs_1.Construct {
|
|
|
44
45
|
return authFlows.map((flow) => flow.toUpperCase());
|
|
45
46
|
}
|
|
46
47
|
getOauthConfig(oauth) {
|
|
47
|
-
if (!oauth
|
|
48
|
+
if (!oauth?.flows?.length) {
|
|
48
49
|
return {};
|
|
49
50
|
}
|
|
50
51
|
return {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ResourceOutputType } from '@lafken/common';
|
|
1
|
+
import type { GetExternalValues, ResourceOutputType } from '@lafken/common';
|
|
2
2
|
import type { CustomAttributesMetadata, StandardAttributeMetadata } from '../../../main';
|
|
3
3
|
export type AuthFlow = 'allow_admin_user_password_auth' | 'allow_custom_auth' | 'allow_user_password_auth' | 'allow_user_srp_auth' | 'allow_refresh_token_auth' | 'allow_user_auth';
|
|
4
4
|
export type OAuthFlow = 'code' | 'client_credentials' | 'implicit';
|
|
@@ -23,6 +23,14 @@ export interface OAuthConfig {
|
|
|
23
23
|
}
|
|
24
24
|
export interface InternalUserClientProps<T extends Function> {
|
|
25
25
|
isExternal?: never;
|
|
26
|
+
/**
|
|
27
|
+
* Name of the Cognito User Pool Client.
|
|
28
|
+
*
|
|
29
|
+
* Specifies a custom name for the User Pool Client resource.
|
|
30
|
+
* If not provided, a default name is derived from the parent
|
|
31
|
+
* User Pool configuration.
|
|
32
|
+
*/
|
|
33
|
+
name?: string;
|
|
26
34
|
/**
|
|
27
35
|
* Defines the authentication flows enabled for the Cognito User Pool Client.
|
|
28
36
|
*
|
|
@@ -157,7 +165,7 @@ export interface ExternalUserClientProps {
|
|
|
157
165
|
* This value is used to look up and integrate with a User Pool Client
|
|
158
166
|
* that was created outside of the framework.
|
|
159
167
|
*/
|
|
160
|
-
clientId: string;
|
|
168
|
+
clientId: string | ((props: GetExternalValues) => string);
|
|
161
169
|
}
|
|
162
170
|
export type UserClientProps<T extends Function> = InternalUserClientProps<T> | ExternalUserClientProps;
|
|
163
171
|
export interface InternalUserPoolClientProps extends InternalUserClientProps<any> {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CognitoUserPoolClient } from '@cdktn/provider-aws/lib/cognito-user-pool-client';
|
|
2
|
+
import { DataAwsCognitoUserPoolClient } from '@cdktn/provider-aws/lib/data-aws-cognito-user-pool-client';
|
|
3
|
+
declare const DataInternalUserPoolClient_base: (new (...args: any[]) => {
|
|
4
|
+
isGlobal(module: import("@lafken/common").ModuleGlobalReferenceNames | (string & {}), id: string): void;
|
|
5
|
+
isDependent(resolveDependency: () => void): void;
|
|
6
|
+
readonly node: import("constructs").Node;
|
|
7
|
+
with(...mixins: import("constructs").IMixin[]): import("constructs").IConstruct;
|
|
8
|
+
toString(): string;
|
|
9
|
+
}) & typeof CognitoUserPoolClient;
|
|
10
|
+
export declare class DataInternalUserPoolClient extends DataInternalUserPoolClient_base {
|
|
11
|
+
}
|
|
12
|
+
declare const DataExternalUserPoolClient_base: (new (...args: any[]) => {
|
|
13
|
+
isGlobal(module: import("@lafken/common").ModuleGlobalReferenceNames | (string & {}), id: string): void;
|
|
14
|
+
isDependent(resolveDependency: () => void): void;
|
|
15
|
+
readonly node: import("constructs").Node;
|
|
16
|
+
with(...mixins: import("constructs").IMixin[]): import("constructs").IConstruct;
|
|
17
|
+
toString(): string;
|
|
18
|
+
}) & typeof DataAwsCognitoUserPoolClient;
|
|
19
|
+
export declare class DataExternalUserPoolClient extends DataExternalUserPoolClient_base {
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataExternalUserPoolClient = exports.DataInternalUserPoolClient = void 0;
|
|
4
|
+
const cognito_user_pool_client_1 = require("@cdktn/provider-aws/lib/cognito-user-pool-client");
|
|
5
|
+
const data_aws_cognito_user_pool_client_1 = require("@cdktn/provider-aws/lib/data-aws-cognito-user-pool-client");
|
|
6
|
+
const resolver_1 = require("@lafken/resolver");
|
|
7
|
+
class DataInternalUserPoolClient extends resolver_1.lafkenResource.make(cognito_user_pool_client_1.CognitoUserPoolClient) {
|
|
8
|
+
}
|
|
9
|
+
exports.DataInternalUserPoolClient = DataInternalUserPoolClient;
|
|
10
|
+
class DataExternalUserPoolClient extends resolver_1.lafkenResource.make(data_aws_cognito_user_pool_client_1.DataAwsCognitoUserPoolClient) {
|
|
11
|
+
}
|
|
12
|
+
exports.DataExternalUserPoolClient = DataExternalUserPoolClient;
|
|
@@ -9,7 +9,7 @@ import type { UserClientProps } from './auth/user-pool-client/user-pool-client.t
|
|
|
9
9
|
export interface ExtendProps {
|
|
10
10
|
scope: Construct;
|
|
11
11
|
userPool: CognitoUserPool | DataAwsCognitoUserPool;
|
|
12
|
-
userPoolClient
|
|
12
|
+
userPoolClient?: CognitoUserPoolClient | DataAwsCognitoUserPoolClient;
|
|
13
13
|
}
|
|
14
14
|
export interface AuthOptions<T extends ClassResource> {
|
|
15
15
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lafken/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Define Cognito User Pools using TypeScript decorators - simplified authentication infrastructure with Lafken",
|
|
6
6
|
"keywords": [
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"reflect-metadata": "^0.2.2",
|
|
53
|
-
"@lafken/resolver": "0.
|
|
53
|
+
"@lafken/resolver": "0.11.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@cdktn/provider-aws": "^23.5.0",
|
|
@@ -63,13 +63,13 @@
|
|
|
63
63
|
"typescript": "6.0.2",
|
|
64
64
|
"unplugin-swc": "^1.5.9",
|
|
65
65
|
"vitest": "^4.1.2",
|
|
66
|
-
"@lafken/common": "0.
|
|
66
|
+
"@lafken/common": "0.11.0"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"@cdktn/provider-aws": ">=23.0.0",
|
|
70
70
|
"cdktn": ">=0.22.0",
|
|
71
71
|
"constructs": "^10.4.5",
|
|
72
|
-
"@lafken/common": "0.
|
|
72
|
+
"@lafken/common": "0.11.0"
|
|
73
73
|
},
|
|
74
74
|
"engines": {
|
|
75
75
|
"node": ">=20.19"
|