@lafken/auth 0.10.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.
- package/LICENCE +21 -0
- package/README.md +493 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +18 -0
- package/lib/main/attribute/attribute.d.ts +86 -0
- package/lib/main/attribute/attribute.js +109 -0
- package/lib/main/attribute/attribute.types.d.ts +90 -0
- package/lib/main/attribute/attribute.types.js +13 -0
- package/lib/main/attribute/index.d.ts +2 -0
- package/lib/main/attribute/index.js +18 -0
- package/lib/main/event/event.d.ts +19 -0
- package/lib/main/event/event.js +26 -0
- package/lib/main/extension/extension.d.ts +60 -0
- package/lib/main/extension/extension.js +74 -0
- package/lib/main/extension/extension.types.d.ts +37 -0
- package/lib/main/extension/extension.types.js +2 -0
- package/lib/main/extension/index.d.ts +1 -0
- package/lib/main/extension/index.js +2 -0
- package/lib/main/index.d.ts +1 -0
- package/lib/main/index.js +17 -0
- package/lib/resolver/auth/auth.d.ts +11 -0
- package/lib/resolver/auth/auth.js +50 -0
- package/lib/resolver/auth/auth.utils.d.ts +2 -0
- package/lib/resolver/auth/auth.utils.js +23 -0
- package/lib/resolver/auth/user-pool/extension/extension.d.ts +8 -0
- package/lib/resolver/auth/user-pool/extension/extension.js +51 -0
- package/lib/resolver/auth/user-pool/extension/extension.types.d.ts +6 -0
- package/lib/resolver/auth/user-pool/extension/extension.types.js +2 -0
- package/lib/resolver/auth/user-pool/external/external.d.ts +14 -0
- package/lib/resolver/auth/user-pool/external/external.js +14 -0
- package/lib/resolver/auth/user-pool/identity-provider/identity-provider.d.ts +13 -0
- package/lib/resolver/auth/user-pool/identity-provider/identity-provider.js +120 -0
- package/lib/resolver/auth/user-pool/identity-provider/identity-provider.types.d.ts +6 -0
- package/lib/resolver/auth/user-pool/identity-provider/identity-provider.types.js +2 -0
- package/lib/resolver/auth/user-pool/internal/internal.d.ts +30 -0
- package/lib/resolver/auth/user-pool/internal/internal.js +332 -0
- package/lib/resolver/auth/user-pool/user-pool.types.d.ts +263 -0
- package/lib/resolver/auth/user-pool/user-pool.types.js +2 -0
- package/lib/resolver/auth/user-pool-client/external/external.d.ts +7 -0
- package/lib/resolver/auth/user-pool-client/external/external.js +16 -0
- package/lib/resolver/auth/user-pool-client/internal/internal.d.ts +14 -0
- package/lib/resolver/auth/user-pool-client/internal/internal.js +115 -0
- package/lib/resolver/auth/user-pool-client/user-pool-client.types.d.ts +169 -0
- package/lib/resolver/auth/user-pool-client/user-pool-client.types.js +2 -0
- package/lib/resolver/index.d.ts +1 -0
- package/lib/resolver/index.js +17 -0
- package/lib/resolver/resolver.d.ts +12 -0
- package/lib/resolver/resolver.js +25 -0
- package/lib/resolver/resolver.types.d.ts +62 -0
- package/lib/resolver/resolver.types.js +2 -0
- package/package.json +87 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import type { ClassResource, ResourceOutputType } from '@lafken/common';
|
|
2
|
+
export type SignInAliases = 'email' | 'phone' | 'preferred_username';
|
|
3
|
+
export type CognitoPlan = 'lite' | 'essentials' | 'plus';
|
|
4
|
+
export type UserVerificationType = 'code' | 'link';
|
|
5
|
+
export type AccountRecovery = 'verified_email' | 'verified_phone_number' | 'admin_only';
|
|
6
|
+
export type AuthFlow = 'admin_user_password' | 'custom' | 'user' | 'user_password' | 'user_srp';
|
|
7
|
+
export type OAuthFlow = 'authorization_code_grant' | 'client_credentials' | 'implicit_code_grant';
|
|
8
|
+
export type OAuthScopes = 'cognito_admin' | 'email' | 'open_id' | 'phone' | 'profile' | {
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
export type AmazonProviderAttributes = 'email' | 'name' | 'postal_code' | 'user_id';
|
|
13
|
+
export type AppleProviderAttributes = 'email' | 'email_verified' | 'first_name' | 'last_name' | 'name';
|
|
14
|
+
export type FacebookProviderAttributes = 'id' | 'email' | 'birthday' | 'gender' | 'id' | 'locale' | 'middle_name' | 'name' | 'first_name' | 'last_name' | 'link' | 'website';
|
|
15
|
+
export type GoogleProviderAttributes = 'sub' | 'name' | 'given_name' | 'family_name' | 'middle_name' | 'nickname' | 'preferred_username' | 'profile' | 'picture' | 'website' | 'email' | 'email_verified' | 'gender' | 'birthdate' | 'zoneinfo' | 'locale' | 'phone_number' | 'phone_number_verified' | 'address' | 'updated_at';
|
|
16
|
+
export type AutoVerifyAttributes = Exclude<SignInAliases, 'preferred_username'>;
|
|
17
|
+
export type UserPoolOutputAttributes = 'arn' | 'domain' | 'endpoint' | 'id';
|
|
18
|
+
export interface PasswordPolicy {
|
|
19
|
+
minLength?: number;
|
|
20
|
+
requireDigits?: boolean;
|
|
21
|
+
requireLowercase?: boolean;
|
|
22
|
+
requireSymbols?: boolean;
|
|
23
|
+
requireUppercase?: boolean;
|
|
24
|
+
validityDays?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface CognitoEmailBase {
|
|
27
|
+
from?: string;
|
|
28
|
+
reply?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface CognitoEmailAccount extends CognitoEmailBase {
|
|
31
|
+
account?: 'cognito';
|
|
32
|
+
}
|
|
33
|
+
export interface SesEmailAccount extends CognitoEmailBase {
|
|
34
|
+
account: 'ses';
|
|
35
|
+
arn: string;
|
|
36
|
+
configurationSet?: string;
|
|
37
|
+
}
|
|
38
|
+
export type EmailConfig = CognitoEmailAccount | SesEmailAccount;
|
|
39
|
+
export interface MfaConfigOff {
|
|
40
|
+
status: 'off';
|
|
41
|
+
}
|
|
42
|
+
export interface MfaConfigOn {
|
|
43
|
+
status: 'optional' | 'required';
|
|
44
|
+
email?: {
|
|
45
|
+
body: string;
|
|
46
|
+
subject: string;
|
|
47
|
+
};
|
|
48
|
+
sms?: string;
|
|
49
|
+
opt?: boolean;
|
|
50
|
+
}
|
|
51
|
+
export interface InvitationMessage {
|
|
52
|
+
email?: {
|
|
53
|
+
subject: string;
|
|
54
|
+
body: string;
|
|
55
|
+
};
|
|
56
|
+
sms?: string;
|
|
57
|
+
}
|
|
58
|
+
export interface UserVerification {
|
|
59
|
+
email?: {
|
|
60
|
+
subject: string;
|
|
61
|
+
body: string;
|
|
62
|
+
type: UserVerificationType;
|
|
63
|
+
};
|
|
64
|
+
sms?: string;
|
|
65
|
+
}
|
|
66
|
+
export type Mfa = MfaConfigOff | MfaConfigOn;
|
|
67
|
+
export type IdentityProviderAttributes<T extends Function, A extends string> = Partial<Record<keyof T['prototype'], A | (string & {})>>;
|
|
68
|
+
export interface CommonIdentityProvider {
|
|
69
|
+
clientId: string;
|
|
70
|
+
clientSecret: string;
|
|
71
|
+
scopes: string[];
|
|
72
|
+
}
|
|
73
|
+
export interface AmazonIdentityProvider<T extends Function> extends CommonIdentityProvider {
|
|
74
|
+
type: 'amazon';
|
|
75
|
+
attributes: IdentityProviderAttributes<T, AmazonProviderAttributes>;
|
|
76
|
+
}
|
|
77
|
+
export interface AppleIdentityProvider<T extends Function> extends Omit<CommonIdentityProvider, 'clientSecret'> {
|
|
78
|
+
type: 'apple';
|
|
79
|
+
keyId: string;
|
|
80
|
+
teamId: string;
|
|
81
|
+
privateKeyValue: string;
|
|
82
|
+
attributes: IdentityProviderAttributes<T, AppleProviderAttributes>;
|
|
83
|
+
}
|
|
84
|
+
export interface FacebookIdentityProvider<T extends Function> extends CommonIdentityProvider {
|
|
85
|
+
type: 'facebook';
|
|
86
|
+
apiVersion?: string;
|
|
87
|
+
attributes: IdentityProviderAttributes<T, FacebookProviderAttributes>;
|
|
88
|
+
}
|
|
89
|
+
export interface GoogleIdentityProvider<T extends Function> extends CommonIdentityProvider {
|
|
90
|
+
type: 'google';
|
|
91
|
+
attributes: IdentityProviderAttributes<T, GoogleProviderAttributes>;
|
|
92
|
+
}
|
|
93
|
+
export interface OidcIdentityProvider<T extends Function> extends CommonIdentityProvider {
|
|
94
|
+
type: 'oidc';
|
|
95
|
+
name: string;
|
|
96
|
+
attributes: IdentityProviderAttributes<T, string>;
|
|
97
|
+
attributesRequestMethod: 'GET' | 'POST';
|
|
98
|
+
authorizeUrl: string;
|
|
99
|
+
tokenUrl: string;
|
|
100
|
+
attributesUrl: string;
|
|
101
|
+
jwksUri: string;
|
|
102
|
+
}
|
|
103
|
+
export type IdentityProvider<T extends ClassResource> = AmazonIdentityProvider<T> | AppleIdentityProvider<T> | FacebookIdentityProvider<T> | GoogleIdentityProvider<T> | OidcIdentityProvider<T>;
|
|
104
|
+
export interface InternalUserPoolProps<T extends ClassResource> {
|
|
105
|
+
isExternal?: never;
|
|
106
|
+
/**
|
|
107
|
+
* Defines the attributes for the Cognito User Pool.
|
|
108
|
+
* Accepts a class decorated with `@Attributes`, where each property can be:
|
|
109
|
+
* - Decorated with `@Standard` to use Cognito's built-in standard attributes, such as email, phone number, or full name.
|
|
110
|
+
* - Decorated with `@Custom` to define custom attributes specific to your application.
|
|
111
|
+
*
|
|
112
|
+
* This allows defining both standard and custom user attributes in a structured way.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* class UserAttributes {
|
|
116
|
+
* @Standard()
|
|
117
|
+
* email!: string;
|
|
118
|
+
*
|
|
119
|
+
* @Custom()
|
|
120
|
+
* favoriteColor!: string;
|
|
121
|
+
* }
|
|
122
|
+
*
|
|
123
|
+
* const userPoolProps: UserPoolProps = {
|
|
124
|
+
* attributes: UserAttributes,
|
|
125
|
+
* };
|
|
126
|
+
*/
|
|
127
|
+
attributes?: T;
|
|
128
|
+
/**
|
|
129
|
+
* Defines which identifiers users can use to sign in to the Cognito User Pool.
|
|
130
|
+
* Supported aliases include:
|
|
131
|
+
* - `username`
|
|
132
|
+
* - `email`
|
|
133
|
+
* - `phone_number`
|
|
134
|
+
*/
|
|
135
|
+
signInAliases?: SignInAliases[];
|
|
136
|
+
/**
|
|
137
|
+
* Defines the password policy for the Cognito User Pool.
|
|
138
|
+
* This allows configuring rules for user passwords, including:
|
|
139
|
+
* - Minimum length
|
|
140
|
+
* - Requirement for uppercase letters
|
|
141
|
+
* - Requirement for lowercase letters
|
|
142
|
+
* - Requirement for numbers
|
|
143
|
+
* - Requirement for special characters
|
|
144
|
+
*/
|
|
145
|
+
passwordPolicy?: PasswordPolicy;
|
|
146
|
+
/**
|
|
147
|
+
* Defines the account recovery options for the Cognito User Pool.
|
|
148
|
+
* This determines how users can recover their accounts if they forget their password,
|
|
149
|
+
* such as via email, phone, or both.
|
|
150
|
+
*
|
|
151
|
+
* Choosing appropriate recovery options improves user experience and security.
|
|
152
|
+
*/
|
|
153
|
+
accountRecovery?: AccountRecovery[];
|
|
154
|
+
/**
|
|
155
|
+
* Specifies which user attributes can be used as the username during sign-up
|
|
156
|
+
* and authentication. Common options include `email` and `phone`.
|
|
157
|
+
*/
|
|
158
|
+
usernameAttributes?: AutoVerifyAttributes[];
|
|
159
|
+
/**
|
|
160
|
+
* Defines which attributes Cognito should automatically verify during sign-up.
|
|
161
|
+
* Only attributes such as `email` or `phone` can be auto-verified.
|
|
162
|
+
*/
|
|
163
|
+
autoVerifyAttributes?: AutoVerifyAttributes[];
|
|
164
|
+
/**
|
|
165
|
+
* Defines the email configuration for the Cognito User Pool.
|
|
166
|
+
* This includes settings such as the sending method (SES or default),
|
|
167
|
+
* sender email address, and reply-to address.
|
|
168
|
+
* It allows customizing how Cognito sends verification and notification emails.
|
|
169
|
+
*/
|
|
170
|
+
email?: EmailConfig;
|
|
171
|
+
/**
|
|
172
|
+
* Defines the Cognito pricing and feature plan for the User Pool.
|
|
173
|
+
*/
|
|
174
|
+
cognitoPlan?: CognitoPlan;
|
|
175
|
+
/**
|
|
176
|
+
* Defines the Multi-Factor Authentication (MFA) configuration for the User Pool.
|
|
177
|
+
* MFA adds an extra layer of security by requiring users to provide additional verification,
|
|
178
|
+
* such as a code sent via SMS or an authenticator app.
|
|
179
|
+
*/
|
|
180
|
+
mfa?: Mfa;
|
|
181
|
+
/**
|
|
182
|
+
* Defines whether users can register (sign up) themselves into the User Pool
|
|
183
|
+
* without an administrator creating their accounts.
|
|
184
|
+
*/
|
|
185
|
+
selfSignUpEnabled?: boolean;
|
|
186
|
+
/**
|
|
187
|
+
* Defines whether sign-in identifiers (such as username or email)
|
|
188
|
+
* are treated as case-sensitive.
|
|
189
|
+
*/
|
|
190
|
+
signInCaseSensitive?: boolean;
|
|
191
|
+
/**
|
|
192
|
+
* Defines the custom invitation message configuration sent to new users
|
|
193
|
+
* when they are created by an admin or imported into the User Pool.
|
|
194
|
+
*/
|
|
195
|
+
invitationMessage?: InvitationMessage;
|
|
196
|
+
/**
|
|
197
|
+
* Defines the messages and methods used to verify a user's account
|
|
198
|
+
* during sign-up in the Cognito User Pool. Verification can be sent via email or SMS.
|
|
199
|
+
*/
|
|
200
|
+
userVerification?: UserVerification;
|
|
201
|
+
/**
|
|
202
|
+
* Defines the external identity providers that can be associated with the UserPool.
|
|
203
|
+
* These providers allow users to authenticate using third-party services
|
|
204
|
+
* such as Google, Facebook, Amazon, Apple or OpenID .
|
|
205
|
+
*/
|
|
206
|
+
identityProviders?: IdentityProvider<T>[];
|
|
207
|
+
/**
|
|
208
|
+
* Defines the list of extensions (triggers) to attach to the Cognito User Pool.
|
|
209
|
+
*
|
|
210
|
+
* This property allows you to add custom logic to different actions performed
|
|
211
|
+
* by the User Pool, such as `preSignUp`, `postConfirmation`, `preAuthentication`, etc.
|
|
212
|
+
*
|
|
213
|
+
* Each extension should be a class decorated with `@AuthExtension`, and its methods
|
|
214
|
+
* must be decorated with `@Trigger`. The `type` of each trigger must be unique
|
|
215
|
+
* to prevent conflicts.
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* // first create an extension class with @AuthExtension decorator
|
|
219
|
+
* {
|
|
220
|
+
* extensions: [PreSignUpClass, PostTokenClass]
|
|
221
|
+
* }
|
|
222
|
+
*/
|
|
223
|
+
extensions?: ClassResource[];
|
|
224
|
+
/**
|
|
225
|
+
* Defines which Cognito User Pool attributes should be exported.
|
|
226
|
+
*
|
|
227
|
+
* Supported attributes are based on Terraform `aws_cognito_user_pool`
|
|
228
|
+
* exported attributes and currently include:
|
|
229
|
+
* - `arn`: ARN of the user pool.
|
|
230
|
+
* - `domain`: Domain prefix associated with the user pool.
|
|
231
|
+
* - `endpoint`: Endpoint name of the user pool.
|
|
232
|
+
* - `id`: ID of the user pool.
|
|
233
|
+
*
|
|
234
|
+
* Each selected attribute can be exported through SSM Parameter Store (`type: 'ssm'`)
|
|
235
|
+
* or Terraform outputs (`type: 'output'`).
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* {
|
|
239
|
+
* output: [
|
|
240
|
+
* { type: 'ssm', name: '/my-user-pool/id', value: 'id' },
|
|
241
|
+
* { type: 'output', name: 'user_pool_arn', value: 'arn' }
|
|
242
|
+
* ]
|
|
243
|
+
* }
|
|
244
|
+
*/
|
|
245
|
+
outputs?: ResourceOutputType<UserPoolOutputAttributes>;
|
|
246
|
+
}
|
|
247
|
+
export interface ExternalUserPoolProps {
|
|
248
|
+
/**
|
|
249
|
+
* Marks the User Pool as an external resource.
|
|
250
|
+
*
|
|
251
|
+
* When set to `true`, the User Pool is not created by the framework.
|
|
252
|
+
* Instead, it references an existing Cognito User Pool using the provided `userPoolId`.
|
|
253
|
+
*/
|
|
254
|
+
isExternal: true;
|
|
255
|
+
/**
|
|
256
|
+
* The ID of the existing Cognito User Pool to reference.
|
|
257
|
+
*
|
|
258
|
+
* This value is used to look up and integrate with a User Pool
|
|
259
|
+
* that was created outside of the framework.
|
|
260
|
+
*/
|
|
261
|
+
userPoolId: string;
|
|
262
|
+
}
|
|
263
|
+
export type UserPoolProps<T extends ClassResource> = InternalUserPoolProps<T> | ExternalUserPoolProps;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DataAwsCognitoUserPoolClient } from '@cdktn/provider-aws/lib/data-aws-cognito-user-pool-client';
|
|
2
|
+
import { Construct } from 'constructs';
|
|
3
|
+
import type { ExternalUserPoolClientProps } from '../user-pool-client.types';
|
|
4
|
+
export declare class ExternalUserPoolClient extends Construct {
|
|
5
|
+
cognitoUserPoolClient: DataAwsCognitoUserPoolClient;
|
|
6
|
+
constructor(scope: Construct, id: string, props: ExternalUserPoolClientProps);
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExternalUserPoolClient = void 0;
|
|
4
|
+
const data_aws_cognito_user_pool_client_1 = require("@cdktn/provider-aws/lib/data-aws-cognito-user-pool-client");
|
|
5
|
+
const constructs_1 = require("constructs");
|
|
6
|
+
class ExternalUserPoolClient extends constructs_1.Construct {
|
|
7
|
+
cognitoUserPoolClient;
|
|
8
|
+
constructor(scope, id, props) {
|
|
9
|
+
super(scope, 'user-pool-client');
|
|
10
|
+
this.cognitoUserPoolClient = new data_aws_cognito_user_pool_client_1.DataAwsCognitoUserPoolClient(this, id, {
|
|
11
|
+
clientId: props.clientId,
|
|
12
|
+
userPoolId: props.userPoolId,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.ExternalUserPoolClient = ExternalUserPoolClient;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CognitoUserPoolClient } from '@cdktn/provider-aws/lib/cognito-user-pool-client';
|
|
2
|
+
import { Construct } from 'constructs';
|
|
3
|
+
import type { InternalUserPoolClientProps } from '../user-pool-client.types';
|
|
4
|
+
export declare class InternalUserPoolClient extends Construct {
|
|
5
|
+
private props;
|
|
6
|
+
cognitoUserPoolClient: CognitoUserPoolClient;
|
|
7
|
+
constructor(scope: Construct, id: string, props: InternalUserPoolClientProps);
|
|
8
|
+
private getRefreshTokenRotation;
|
|
9
|
+
private getExplicitAuthFlows;
|
|
10
|
+
private getOauthConfig;
|
|
11
|
+
private getValidity;
|
|
12
|
+
private resolveValidityUnit;
|
|
13
|
+
private getAttributes;
|
|
14
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InternalUserPoolClient = void 0;
|
|
4
|
+
const cognito_user_pool_client_1 = require("@cdktn/provider-aws/lib/cognito-user-pool-client");
|
|
5
|
+
const resolver_1 = require("@lafken/resolver");
|
|
6
|
+
const constructs_1 = require("constructs");
|
|
7
|
+
const auth_utils_1 = require("../../auth.utils");
|
|
8
|
+
class InternalUserPoolClient extends constructs_1.Construct {
|
|
9
|
+
props;
|
|
10
|
+
cognitoUserPoolClient;
|
|
11
|
+
constructor(scope, id, props) {
|
|
12
|
+
super(scope, 'user-pool-client');
|
|
13
|
+
this.props = props;
|
|
14
|
+
this.cognitoUserPoolClient = new cognito_user_pool_client_1.CognitoUserPoolClient(this, id, {
|
|
15
|
+
...this.getValidity(props),
|
|
16
|
+
...this.getOauthConfig(props.oauth),
|
|
17
|
+
name: id,
|
|
18
|
+
userPoolId: props.userPoolId,
|
|
19
|
+
enableTokenRevocation: props.enableTokenRevocation ?? true,
|
|
20
|
+
generateSecret: props.generateSecret ?? false,
|
|
21
|
+
preventUserExistenceErrors: props.preventUserExistenceErrors !== false ? 'ENABLED' : 'LEGACY',
|
|
22
|
+
explicitAuthFlows: this.getExplicitAuthFlows(props.authFlows),
|
|
23
|
+
refreshTokenRotation: this.getRefreshTokenRotation(props.refreshTokenRotationGracePeriod),
|
|
24
|
+
readAttributes: this.getAttributes(props.readAttributes),
|
|
25
|
+
writeAttributes: this.getAttributes(props.writeAttributes),
|
|
26
|
+
});
|
|
27
|
+
new resolver_1.ResourceOutput(this.cognitoUserPoolClient, props.outputs);
|
|
28
|
+
}
|
|
29
|
+
getRefreshTokenRotation(period) {
|
|
30
|
+
if (!period) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
return [
|
|
34
|
+
{
|
|
35
|
+
feature: 'ENABLED',
|
|
36
|
+
retryGracePeriodSeconds: period,
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
getExplicitAuthFlows(authFlows) {
|
|
41
|
+
if (!authFlows?.length) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
return authFlows.map((flow) => flow.toUpperCase());
|
|
45
|
+
}
|
|
46
|
+
getOauthConfig(oauth) {
|
|
47
|
+
if (!oauth || !oauth.flows?.length) {
|
|
48
|
+
return {};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
allowedOauthFlowsUserPoolClient: true,
|
|
52
|
+
allowedOauthFlows: oauth.flows,
|
|
53
|
+
allowedOauthScopes: oauth.scopes,
|
|
54
|
+
callbackUrls: oauth.callbackUrls,
|
|
55
|
+
defaultRedirectUri: oauth.defaultRedirectUri,
|
|
56
|
+
logoutUrls: oauth.logoutUrls,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
getValidity(props) {
|
|
60
|
+
const accessToken = this.resolveValidityUnit(props.validity?.accessToken);
|
|
61
|
+
const idToken = this.resolveValidityUnit(props.validity?.idToken);
|
|
62
|
+
const refreshToken = this.resolveValidityUnit(props.validity?.refreshToken);
|
|
63
|
+
return {
|
|
64
|
+
authSessionValidity: props.validity?.authSession ?? 3,
|
|
65
|
+
accessTokenValidity: accessToken.value,
|
|
66
|
+
idTokenValidity: idToken.value,
|
|
67
|
+
refreshTokenValidity: refreshToken.value,
|
|
68
|
+
tokenValidityUnits: accessToken.unit || idToken.unit || refreshToken.unit
|
|
69
|
+
? [
|
|
70
|
+
{
|
|
71
|
+
accessToken: accessToken.unit,
|
|
72
|
+
refreshToken: refreshToken.unit,
|
|
73
|
+
idToken: idToken.unit,
|
|
74
|
+
},
|
|
75
|
+
]
|
|
76
|
+
: undefined,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
resolveValidityUnit(value) {
|
|
80
|
+
if (!value) {
|
|
81
|
+
return {};
|
|
82
|
+
}
|
|
83
|
+
if (typeof value === 'number') {
|
|
84
|
+
return {
|
|
85
|
+
value,
|
|
86
|
+
unit: 'hours',
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
value: value.value,
|
|
91
|
+
unit: value.type,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
getAttributes(selectedAttributes) {
|
|
95
|
+
if (!selectedAttributes?.length) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const attributes = [];
|
|
99
|
+
for (const providerAttribute of selectedAttributes) {
|
|
100
|
+
const attribute = this.props.attributeByName[providerAttribute];
|
|
101
|
+
if (!attribute) {
|
|
102
|
+
throw new Error(`Attribute ${providerAttribute} not exist in attribute class`);
|
|
103
|
+
}
|
|
104
|
+
const attributeName = attribute.attributeType === 'standard'
|
|
105
|
+
? auth_utils_1.mapUserAttributes[attribute.name]
|
|
106
|
+
: `custom:${attribute.name}`;
|
|
107
|
+
if (!attributeName) {
|
|
108
|
+
throw new Error(`Attribute ${attribute.name} is not a standard attribute`);
|
|
109
|
+
}
|
|
110
|
+
attributes.push(attributeName);
|
|
111
|
+
}
|
|
112
|
+
return attributes;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.InternalUserPoolClient = InternalUserPoolClient;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import type { ResourceOutputType } from '@lafken/common';
|
|
2
|
+
import type { CustomAttributesMetadata, StandardAttributeMetadata } from '../../../main';
|
|
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
|
+
export type OAuthFlow = 'code' | 'client_credentials' | 'implicit';
|
|
5
|
+
export type OAuthScopes = 'aws.cognito.signin.user.admin' | 'email' | 'openid' | 'phone' | 'profile' | (string & {});
|
|
6
|
+
export type UserPoolClientOutputAttributes = 'clientSecret' | 'id';
|
|
7
|
+
export interface ValidityUnit {
|
|
8
|
+
type: 'seconds' | 'minutes' | 'hours' | 'days';
|
|
9
|
+
value: number;
|
|
10
|
+
}
|
|
11
|
+
export interface Validity {
|
|
12
|
+
authSession?: number;
|
|
13
|
+
accessToken?: number | ValidityUnit;
|
|
14
|
+
idToken?: number | ValidityUnit;
|
|
15
|
+
refreshToken?: number | ValidityUnit;
|
|
16
|
+
}
|
|
17
|
+
export interface OAuthConfig {
|
|
18
|
+
callbackUrls?: string[];
|
|
19
|
+
defaultRedirectUri?: string;
|
|
20
|
+
flows?: OAuthFlow[];
|
|
21
|
+
logoutUrls?: string[];
|
|
22
|
+
scopes?: OAuthScopes[];
|
|
23
|
+
}
|
|
24
|
+
export interface InternalUserClientProps<T extends Function> {
|
|
25
|
+
isExternal?: never;
|
|
26
|
+
/**
|
|
27
|
+
* Defines the authentication flows enabled for the Cognito User Pool Client.
|
|
28
|
+
*
|
|
29
|
+
* This property specifies which authentication mechanisms are allowed
|
|
30
|
+
* when users attempt to sign in. It supports standard, custom, and admin-based
|
|
31
|
+
* authentication flows.
|
|
32
|
+
*
|
|
33
|
+
* Available values include:
|
|
34
|
+
* - `'admin_no_srp_auth'`: Admin-initiated authentication without SRP (Secure Remote Password).
|
|
35
|
+
* - `'custom_auth_flow_only'`: Only allows a custom authentication flow.
|
|
36
|
+
* - `'user_password_auth'`: Standard username and password authentication.
|
|
37
|
+
* - `'allow_admin_user_password_auth'`: Admin can authenticate with username and password.
|
|
38
|
+
* - `'allow_custom_auth'`: Allows custom authentication flows.
|
|
39
|
+
* - `'allow_user_password_auth'`: Users can authenticate with username and password.
|
|
40
|
+
* - `'allow_user_srp_auth'`: Users can authenticate with SRP (Secure Remote Password).
|
|
41
|
+
* - `'allow_refresh_token_auth'`: Enables refreshing authentication tokens.
|
|
42
|
+
* - `'allow_user_auth'`: Enables general user authentication.
|
|
43
|
+
*/
|
|
44
|
+
authFlows?: AuthFlow[];
|
|
45
|
+
/**
|
|
46
|
+
* Defines the validity durations for the authentication tokens and sessions
|
|
47
|
+
* of the Cognito User Pool Client.
|
|
48
|
+
*
|
|
49
|
+
* This property allows you to specify how long different elements of the
|
|
50
|
+
* authentication process remain valid before expiring.
|
|
51
|
+
*
|
|
52
|
+
* Available options include:
|
|
53
|
+
* - `authSession`: Duration of the authentication session in seconds.
|
|
54
|
+
* - `accessToken`: Duration of the access token.
|
|
55
|
+
* - `idToken`: Duration of the ID token.
|
|
56
|
+
* - `refreshToken`: Duration of the refresh token.
|
|
57
|
+
*/
|
|
58
|
+
validity?: Validity;
|
|
59
|
+
/**
|
|
60
|
+
* Defines whether token revocation is enabled for the Cognito User Pool Client.
|
|
61
|
+
*
|
|
62
|
+
* When set to `true`, it allows tokens (access, ID, and refresh tokens)
|
|
63
|
+
* issued to users to be explicitly revoked before their natural expiration.
|
|
64
|
+
* This enhances security by allowing administrators to invalidate tokens
|
|
65
|
+
* in case of suspicious activity or when a user should no longer have access.
|
|
66
|
+
*/
|
|
67
|
+
enableTokenRevocation?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Defines whether the Cognito User Pool Client should generate a client secret.
|
|
70
|
+
*
|
|
71
|
+
* When set to `true`, a secret will be generated and associated with the client.
|
|
72
|
+
* This is useful for server-side applications where the client secret can
|
|
73
|
+
* be securely stored and used for authentication flows, such as the
|
|
74
|
+
* client credentials or authorization code flows.
|
|
75
|
+
*/
|
|
76
|
+
generateSecret?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Defines the OAuth 2.0 configuration for the Cognito User Pool Client.
|
|
79
|
+
*
|
|
80
|
+
* This property allows you to specify how the client interacts with
|
|
81
|
+
* external OAuth flows, including allowed redirect URLs, enabled flows,
|
|
82
|
+
* scopes, and logout URLs.
|
|
83
|
+
*
|
|
84
|
+
* Available options:
|
|
85
|
+
* - `callbackUrls`: An array of URLs where Cognito will redirect after successful authentication.
|
|
86
|
+
* - `defaultRedirectUri`: The default URL used for redirection if none is specified.
|
|
87
|
+
* - `flows`: List of OAuth flows enabled for the client (e.g., authorization code, implicit).
|
|
88
|
+
* - `logoutUrls`: URLs where users are redirected after logging out.
|
|
89
|
+
* - `scopes`: The scopes allowed for this client, defining the access privileges.
|
|
90
|
+
*/
|
|
91
|
+
oauth?: OAuthConfig;
|
|
92
|
+
/**
|
|
93
|
+
* Defines whether to prevent user existence errors for the Cognito User Pool Client.
|
|
94
|
+
*
|
|
95
|
+
* When set to `true`, the client will not reveal whether a user exists or not
|
|
96
|
+
* during authentication attempts. This helps to prevent information leakage
|
|
97
|
+
* about registered users, enhancing security against user enumeration attacks
|
|
98
|
+
*/
|
|
99
|
+
preventUserExistenceErrors?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Defines which attributes of the Cognito User Pool Client are readable.
|
|
102
|
+
*
|
|
103
|
+
* This property allows you to specify a list of attribute names that
|
|
104
|
+
* can be accessed by the client. Only the attributes included in this
|
|
105
|
+
* list will be returned when querying user information.
|
|
106
|
+
*/
|
|
107
|
+
readAttributes?: (keyof T['prototype'])[];
|
|
108
|
+
/**
|
|
109
|
+
* Defines which attributes of the Cognito User Pool Client are writable.
|
|
110
|
+
*
|
|
111
|
+
* This property allows you to specify a list of attribute names that
|
|
112
|
+
* the client is allowed to modify. Only the attributes included in this
|
|
113
|
+
* list can be updated through client operations.
|
|
114
|
+
*/
|
|
115
|
+
writeAttributes?: (keyof T['prototype'])[];
|
|
116
|
+
/**
|
|
117
|
+
* Defines the grace period (in seconds) for refresh token rotation in the Cognito User Pool Client.
|
|
118
|
+
*
|
|
119
|
+
* When refresh token rotation is enabled, a new refresh token is issued each time
|
|
120
|
+
* the user uses an existing refresh token. This property sets a grace period during
|
|
121
|
+
* which both the old and new refresh tokens are valid, allowing smooth token rotation
|
|
122
|
+
* without immediately invalidating active sessions.
|
|
123
|
+
*/
|
|
124
|
+
refreshTokenRotationGracePeriod?: number;
|
|
125
|
+
/**
|
|
126
|
+
* Defines which Cognito User Pool Client attributes should be exported.
|
|
127
|
+
*
|
|
128
|
+
* Supported attributes are based on Terraform `aws_cognito_user_pool_client`
|
|
129
|
+
* exported attributes and currently include:
|
|
130
|
+
* - `clientSecret`: Client secret of the user pool client.
|
|
131
|
+
* - `id`: ID of the user pool client.
|
|
132
|
+
*
|
|
133
|
+
* Each selected attribute can be exported through SSM Parameter Store (`type: 'ssm'`)
|
|
134
|
+
* or Terraform outputs (`type: 'output'`).
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* {
|
|
138
|
+
* output: [
|
|
139
|
+
* { type: 'ssm', name: '/my-user-pool-client/id', value: 'id' },
|
|
140
|
+
* { type: 'output', name: 'user_pool_client_secret', value: 'clientSecret' }
|
|
141
|
+
* ]
|
|
142
|
+
* }
|
|
143
|
+
*/
|
|
144
|
+
outputs?: ResourceOutputType<UserPoolClientOutputAttributes>;
|
|
145
|
+
}
|
|
146
|
+
export interface ExternalUserClientProps {
|
|
147
|
+
/**
|
|
148
|
+
* Marks the User Pool as an external resource.
|
|
149
|
+
*
|
|
150
|
+
* When set to `true`, the User Pool Client is not created by the framework.
|
|
151
|
+
* Instead, it references an existing Cognito User Pool Client using the provided `userPoolId`.
|
|
152
|
+
*/
|
|
153
|
+
isExternal: true;
|
|
154
|
+
/**
|
|
155
|
+
* The ID of the existing Cognito User Pool Client to reference.
|
|
156
|
+
*
|
|
157
|
+
* This value is used to look up and integrate with a User Pool Client
|
|
158
|
+
* that was created outside of the framework.
|
|
159
|
+
*/
|
|
160
|
+
clientId: string;
|
|
161
|
+
}
|
|
162
|
+
export type UserClientProps<T extends Function> = InternalUserClientProps<T> | ExternalUserClientProps;
|
|
163
|
+
export interface InternalUserPoolClientProps extends InternalUserClientProps<any> {
|
|
164
|
+
userPoolId: string;
|
|
165
|
+
attributeByName: Record<string, CustomAttributesMetadata | StandardAttributeMetadata>;
|
|
166
|
+
}
|
|
167
|
+
export interface ExternalUserPoolClientProps extends ExternalUserClientProps {
|
|
168
|
+
userPoolId: string;
|
|
169
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './resolver';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./resolver"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ClassResource } from '@lafken/common';
|
|
2
|
+
import type { AppModule, ResolverType } from '@lafken/resolver';
|
|
3
|
+
import type { AuthOptions } from './resolver.types';
|
|
4
|
+
export declare class AuthResolver<T extends ClassResource = ClassResource> implements ResolverType {
|
|
5
|
+
protected options: AuthOptions<T>;
|
|
6
|
+
type: "AUTHENTICATION";
|
|
7
|
+
private auth;
|
|
8
|
+
constructor(options: AuthOptions<T>);
|
|
9
|
+
beforeCreate(scope: AppModule): Promise<void>;
|
|
10
|
+
create(module: AppModule): Promise<void>;
|
|
11
|
+
afterCreate(): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthResolver = void 0;
|
|
4
|
+
const cdktn_1 = require("cdktn");
|
|
5
|
+
const extension_1 = require("../main/extension/extension");
|
|
6
|
+
const auth_1 = require("./auth/auth");
|
|
7
|
+
class AuthResolver {
|
|
8
|
+
options;
|
|
9
|
+
type = extension_1.RESOURCE_TYPE;
|
|
10
|
+
auth;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
}
|
|
14
|
+
async beforeCreate(scope) {
|
|
15
|
+
this.auth = new auth_1.Auth(scope, this.options.name, this.options);
|
|
16
|
+
this.auth.create();
|
|
17
|
+
}
|
|
18
|
+
async create(module) {
|
|
19
|
+
cdktn_1.Annotations.of(module).addError('Auth has no resources to create');
|
|
20
|
+
}
|
|
21
|
+
async afterCreate() {
|
|
22
|
+
await this.auth.callExtends();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.AuthResolver = AuthResolver;
|