/
user-pool-resource-server.ts
115 lines (99 loc) · 2.76 KB
/
user-pool-resource-server.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { Construct } from 'constructs';
import { CfnUserPoolResourceServer } from './cognito.generated';
import { IUserPool } from './user-pool';
import { IResource, Resource } from '../../core';
/**
* Represents a Cognito user pool resource server
*/
export interface IUserPoolResourceServer extends IResource {
/**
* Resource server id
* @attribute
*/
readonly userPoolResourceServerId: string;
}
/**
* Props to initialize ResourceServerScope
*/
export interface ResourceServerScopeProps {
/**
* The name of the scope
*/
readonly scopeName: string;
/**
* A description of the scope.
*/
readonly scopeDescription: string;
}
/**
* A scope for ResourceServer
*/
export class ResourceServerScope {
/**
* The name of the scope
*/
public readonly scopeName: string;
/**
* A description of the scope.
*/
public readonly scopeDescription: string;
constructor(props: ResourceServerScopeProps) {
this.scopeName = props.scopeName;
this.scopeDescription = props.scopeDescription;
}
}
/**
* Options to create a UserPoolResourceServer
*/
export interface UserPoolResourceServerOptions {
/**
* A unique resource server identifier for the resource server.
*/
readonly identifier: string;
/**
* A friendly name for the resource server.
* @default - same as `identifier`
*/
readonly userPoolResourceServerName?: string;
/**
* Oauth scopes
* @default - No scopes will be added
*/
readonly scopes?: ResourceServerScope[];
}
/**
* Properties for the UserPoolResourceServer construct
*/
export interface UserPoolResourceServerProps extends UserPoolResourceServerOptions {
/**
* The user pool to add this resource server to
*/
readonly userPool: IUserPool;
}
/**
* Defines a User Pool OAuth2.0 Resource Server
*/
export class UserPoolResourceServer extends Resource implements IUserPoolResourceServer {
/**
* Import a user pool resource client given its id.
*/
public static fromUserPoolResourceServerId(scope: Construct, id: string, userPoolResourceServerId: string): IUserPoolResourceServer {
class Import extends Resource implements IUserPoolResourceServer {
public readonly userPoolResourceServerId = userPoolResourceServerId;
}
return new Import(scope, id);
}
public readonly userPoolResourceServerId: string;
constructor(scope: Construct, id: string, props: UserPoolResourceServerProps) {
super(scope, id, {
physicalName: props.identifier,
});
const resource = new CfnUserPoolResourceServer(this, 'Resource', {
identifier: this.physicalName,
name: props.userPoolResourceServerName ?? this.physicalName,
scopes: props.scopes,
userPoolId: props.userPool.userPoolId,
});
this.userPoolResourceServerId = resource.ref;
}
}