@fy-stack/auth-construct 0.0.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/README.md +7 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/lib/auth-construct.d.ts +20 -0
- package/dist/lib/auth-construct.d.ts.map +1 -0
- package/dist/lib/auth-construct.js +63 -0
- package/dist/lib/types.d.ts +14 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +2 -0
- package/package.json +22 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthConstruct = void 0;
|
|
4
|
+
var auth_construct_1 = require("./lib/auth-construct");
|
|
5
|
+
Object.defineProperty(exports, "AuthConstruct", { enumerable: true, get: function () { return auth_construct_1.AuthConstruct; } });
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Attachable, Grantable } from '@fy-stack/types';
|
|
2
|
+
import * as cognito from 'aws-cdk-lib/aws-cognito';
|
|
3
|
+
import * as iam from 'aws-cdk-lib/aws-iam';
|
|
4
|
+
import { Construct } from 'constructs';
|
|
5
|
+
import { AuthConstructProps } from './types';
|
|
6
|
+
export declare class AuthConstruct extends Construct implements Attachable, Grantable {
|
|
7
|
+
userPool: cognito.UserPool;
|
|
8
|
+
domain: cognito.UserPoolDomain;
|
|
9
|
+
client: cognito.UserPoolClient;
|
|
10
|
+
constructor(scope: Construct, id: string, props: AuthConstructProps);
|
|
11
|
+
attachable(): {
|
|
12
|
+
arn: string;
|
|
13
|
+
id: string;
|
|
14
|
+
domainName: string;
|
|
15
|
+
clientId: string;
|
|
16
|
+
clientSecret: string;
|
|
17
|
+
};
|
|
18
|
+
grantable(grant: iam.IGrantable): void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=auth-construct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-construct.d.ts","sourceRoot":"","sources":["../../src/lib/auth-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;AACnD,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C,qBAAa,aAAc,SAAQ,SAAU,YAAW,UAAU,EAAE,SAAS;IACpE,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC;IAC3B,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC;IAC/B,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC;gBAE1B,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB;IAyCnE,UAAU;;;;;;;IAUV,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,UAAU;CAQhC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthConstruct = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
6
|
+
const cognito = tslib_1.__importStar(require("aws-cdk-lib/aws-cognito"));
|
|
7
|
+
const iam = tslib_1.__importStar(require("aws-cdk-lib/aws-iam"));
|
|
8
|
+
const constructs_1 = require("constructs");
|
|
9
|
+
class AuthConstruct extends constructs_1.Construct {
|
|
10
|
+
userPool;
|
|
11
|
+
domain;
|
|
12
|
+
client;
|
|
13
|
+
constructor(scope, id, props) {
|
|
14
|
+
super(scope, id);
|
|
15
|
+
this.userPool = new cognito.UserPool(this, 'UserPool', {
|
|
16
|
+
deletionProtection: true,
|
|
17
|
+
selfSignUpEnabled: true,
|
|
18
|
+
signInCaseSensitive: false,
|
|
19
|
+
});
|
|
20
|
+
this.domain = new cognito.UserPoolDomain(this, 'UserPoolDomain', {
|
|
21
|
+
userPool: this.userPool,
|
|
22
|
+
cognitoDomain: { domainPrefix: id.toLowerCase() },
|
|
23
|
+
});
|
|
24
|
+
this.client = new cognito.UserPoolClient(this, 'WebClient', {
|
|
25
|
+
userPool: this.userPool,
|
|
26
|
+
authFlows: {
|
|
27
|
+
userPassword: true,
|
|
28
|
+
userSrp: true,
|
|
29
|
+
adminUserPassword: true,
|
|
30
|
+
},
|
|
31
|
+
accessTokenValidity: aws_cdk_lib_1.Duration.hours(props.token?.accessTokenValidity ?? 24),
|
|
32
|
+
refreshTokenValidity: aws_cdk_lib_1.Duration.hours(props.token?.refreshTokenValidity ?? 720),
|
|
33
|
+
generateSecret: true,
|
|
34
|
+
});
|
|
35
|
+
if (props.groups?.length) {
|
|
36
|
+
for (const i in props.groups) {
|
|
37
|
+
new cognito.CfnUserPoolGroup(this, `${props.groups[i]}Group`, {
|
|
38
|
+
userPoolId: this.userPool.userPoolId,
|
|
39
|
+
precedence: Number(i) + 1,
|
|
40
|
+
groupName: props.groups[i],
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
attachable() {
|
|
46
|
+
return {
|
|
47
|
+
arn: this?.userPool.userPoolArn,
|
|
48
|
+
id: this?.userPool.userPoolId,
|
|
49
|
+
domainName: this.domain.domainName,
|
|
50
|
+
clientId: this?.client.userPoolClientId,
|
|
51
|
+
clientSecret: this?.client.userPoolClientSecret.unsafeUnwrap(),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
grantable(grant) {
|
|
55
|
+
new iam.PolicyStatement({
|
|
56
|
+
effect: iam.Effect.ALLOW,
|
|
57
|
+
actions: ['cognito-idp:*', 'cognito-identity:*'],
|
|
58
|
+
resources: [this.userPool.userPoolArn],
|
|
59
|
+
principals: [grant.grantPrincipal],
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.AuthConstruct = AuthConstruct;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface AuthConstructProps {
|
|
2
|
+
/** User pool group names */
|
|
3
|
+
groups?: string[];
|
|
4
|
+
/**
|
|
5
|
+
* Token options
|
|
6
|
+
* */
|
|
7
|
+
token?: {
|
|
8
|
+
/** Access token validity in hours */
|
|
9
|
+
accessTokenValidity?: number;
|
|
10
|
+
/** Refresh token validity in hours */
|
|
11
|
+
refreshTokenValidity?: number;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB;;SAEK;IACL,KAAK,CAAC,EAAE;QACN,qCAAqC;QACrC,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,sCAAsC;QACtC,oBAAoB,CAAC,EAAE,MAAM,CAAC;KAC/B,CAAC;CACH"}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fy-stack/auth-construct",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"tslib": "^2.3.0"
|
|
6
|
+
},
|
|
7
|
+
"peerDependencies": {
|
|
8
|
+
"aws-cdk-lib": "2.164.1",
|
|
9
|
+
"constructs": "10.4.2",
|
|
10
|
+
"@fy-stack/types": "0.0.1"
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"module": "./dist/index.mjs",
|
|
14
|
+
"typings": "./dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"!**/*.tsbuildinfo"
|
|
18
|
+
],
|
|
19
|
+
"nx": {
|
|
20
|
+
"name": "auth-construct"
|
|
21
|
+
}
|
|
22
|
+
}
|