Skip to content

Commit 90a7c49

Browse files
awslujartpascual
andauthored
Reference Auth (#2118)
* feat: reference auth basic setup * chore: factory basic tests * chore: update api * chore: add ref auth package as dependency to backend-auth * chore: lint * chore: add tests for construct * chore: cleanup tsconfig * chore: add changeset * chore: fix tests inputs * chore: update tests * fix: update resource provider types * chore: update api * feat: reference auth outputs * chore: add tests * chore: fix test * chore: cleanup reused variables * chore: changeset * chore: cleanup changeset * chore: cleanup * chore: cleanup changesets, lockfile, and api * chore: fix mismatched output structure * chore: refactor and add tests * chore: add more tests for identity pool errors * chore: cleanup * chore: fix test * chore: add role tests * chore: add tests for user pool client * chore: cleanup * chore: refactor * chore: fix api * chore: undo changes to concurrent workspace script * chore: add missing roles permission * chore: update expected IAM policy permissions for identity pool * fix: make sure to throw on errors when using Provider framework * chore: refactor * chore: cleanup * chore: more cleanup * chore: check for alias attributes and fix tests * chore: add support for validating group roles exist for user pool * chore: update package-lock file * chore: add checks for oauth validation * chore: fix typo * chore: eliminate forcing updates on any change * chore: remove commented out code * chore: merge factory count into single count for all auth factories * chore: move sample data and npmignore it * chore: cleanup * chore: fix path * chore: update package lock * chore: update package-lock * chore: move construct into backend-auth * chore: update api * chore: update changeset * chore: cleanup * chore: move props type to factory * chore: add working setup for e2e resources in ref auth (#2122) * chore: add working setup for e2e resources in ref auth * feed pr base sha and ref into envs before scripts (#2168) * feed pr base sha and ref into envs before scripts * removing empty file * chore: update names to use test prefix * chore: remove extra hyphen * chore: fix cleanup and add sandbox test * chore: make sure to throw if error describing stack is unknown --------- Co-authored-by: Roshane Pascual <[email protected]> * chore: add bsd-3-clause-clear license to allow list * chore: cleanup * chore: make lambda deps dev dependencies * chore: revert license changes * chore: remove tag mechanism as not needed for cleanup --------- Co-authored-by: Roshane Pascual <[email protected]>
1 parent 12cf209 commit 90a7c49

40 files changed

+3485
-17
lines changed

.changeset/good-pugs-rescue.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@aws-amplify/auth-construct': minor
3+
'@aws-amplify/backend-auth': minor
4+
'@aws-amplify/backend-data': minor
5+
'@aws-amplify/plugin-types': minor
6+
'@aws-amplify/backend': minor
7+
---
8+
9+
Add support for referenceAuth.

.changeset/spicy-rules-speak.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ For local testing we recommend writing unit tests that exercise the code you are
8282
npm run test:dir packages/<package name>/lib/<file-name>.test.ts
8383
```
8484

85+
> Note: If your test depends on \_\_dirname or import.meta.url paths, you may see errors resolving paths if you specify the entire path to the test file. You should specify just the `packages/<package name>` portion of the test you are running.
86+
8587
> Note: You must rebuild using `npm run build` for tests to pick up your changes.
8688
8789
Sometimes it's nice to have a test project to use as a testing environment for local changes. You can create test projects in the `local-testing` directory using

package-lock.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/auth-construct/src/construct.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ export class AmplifyAuth
223223
userPoolClient,
224224
authenticatedUserIamRole: auth,
225225
unauthenticatedUserIamRole: unAuth,
226+
identityPoolId: identityPool.ref,
226227
cfnResources: {
227228
cfnUserPool,
228229
cfnUserPoolClient,

packages/backend-auth/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
# Then ignore test js and ts declaration files
1111
*.test.js
1212
*.test.d.ts
13+
**/test-resources/**
1314

1415
# This leaves us with including only js and ts declaration files of functional code

packages/backend-auth/API.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
import { AmazonProviderProps } from '@aws-amplify/auth-construct';
88
import { AmplifyFunction } from '@aws-amplify/plugin-types';
99
import { AppleProviderProps } from '@aws-amplify/auth-construct';
10+
import { AuthOutput } from '@aws-amplify/backend-output-schemas';
1011
import { AuthProps } from '@aws-amplify/auth-construct';
1112
import { AuthResources } from '@aws-amplify/plugin-types';
1213
import { AuthRoleName } from '@aws-amplify/plugin-types';
14+
import { BackendOutputStorageStrategy } from '@aws-amplify/plugin-types';
1315
import { BackendSecret } from '@aws-amplify/plugin-types';
1416
import { ConstructFactory } from '@aws-amplify/plugin-types';
1517
import { ConstructFactoryGetInstanceProps } from '@aws-amplify/plugin-types';
@@ -19,6 +21,7 @@ import { FunctionResources } from '@aws-amplify/plugin-types';
1921
import { GoogleProviderProps } from '@aws-amplify/auth-construct';
2022
import { IFunction } from 'aws-cdk-lib/aws-lambda';
2123
import { OidcProviderProps } from '@aws-amplify/auth-construct';
24+
import { ReferenceAuthResources } from '@aws-amplify/plugin-types';
2225
import { ResourceAccessAcceptor } from '@aws-amplify/plugin-types';
2326
import { ResourceAccessAcceptorFactory } from '@aws-amplify/plugin-types';
2427
import { ResourceProvider } from '@aws-amplify/plugin-types';
@@ -48,6 +51,11 @@ export type AmplifyAuthProps = Expand<Omit<AuthProps, 'outputStorageStrategy' |
4851
};
4952
}>;
5053

54+
// @public (undocumented)
55+
export type AmplifyReferenceAuthProps = Expand<Omit<ReferenceAuthProps, 'outputStorageStrategy'> & {
56+
access?: AuthAccessGenerator;
57+
}>;
58+
5159
// @public
5260
export type AppleProviderFactoryProps = Omit<AppleProviderProps, 'clientId' | 'teamId' | 'keyId' | 'privateKey'> & {
5361
clientId: BackendSecret;
@@ -86,6 +94,9 @@ export type AuthLoginWithFactoryProps = Omit<AuthProps['loginWith'], 'externalPr
8694
// @public (undocumented)
8795
export type BackendAuth = ResourceProvider<AuthResources> & ResourceAccessAcceptorFactory<AuthRoleName | string> & StackProvider;
8896

97+
// @public (undocumented)
98+
export type BackendReferenceAuth = ResourceProvider<ReferenceAuthResources> & ResourceAccessAcceptorFactory<AuthRoleName | string> & StackProvider;
99+
89100
// @public
90101
export type CustomEmailSender = {
91102
handler: ConstructFactory<AmplifyFunction> | IFunction;
@@ -130,6 +141,22 @@ export type OidcProviderFactoryProps = Omit<OidcProviderProps, 'clientId' | 'cli
130141
clientSecret: BackendSecret;
131142
};
132143

144+
// @public
145+
export const referenceAuth: (props: AmplifyReferenceAuthProps) => ConstructFactory<BackendReferenceAuth>;
146+
147+
// @public (undocumented)
148+
export type ReferenceAuthProps = {
149+
outputStorageStrategy?: BackendOutputStorageStrategy<AuthOutput>;
150+
userPoolId: string;
151+
identityPoolId: string;
152+
userPoolClientId: string;
153+
authRoleArn: string;
154+
unauthRoleArn: string;
155+
groups?: {
156+
[groupName: string]: string;
157+
};
158+
};
159+
133160
// (No @packageDocumentation comment for this package)
134161

135162
```

packages/backend-auth/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@
2020
"license": "Apache-2.0",
2121
"dependencies": {
2222
"@aws-amplify/auth-construct": "^1.4.0",
23+
"@aws-amplify/backend-output-schemas": "^1.4.0",
2324
"@aws-amplify/backend-output-storage": "^1.1.3",
2425
"@aws-amplify/plugin-types": "^1.3.1"
2526
},
2627
"devDependencies": {
2728
"@aws-amplify/backend-platform-test-stubs": "^0.3.6",
28-
"@aws-amplify/platform-core": "^1.0.6"
29+
"@aws-amplify/platform-core": "^1.0.6",
30+
"@aws-sdk/client-cognito-identity-provider": "^3.624.0",
31+
"@aws-sdk/client-cognito-identity": "^3.624.0",
32+
"@types/aws-lambda": "^8.10.119",
33+
"aws-lambda": "^1.0.7"
2934
},
3035
"peerDependencies": {
3136
"aws-cdk-lib": "^2.158.0",

packages/backend-auth/src/factory.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ void describe('AmplifyAuthFactory', () => {
153153
},
154154
new AmplifyUserError('MultipleSingletonResourcesError', {
155155
message:
156-
'Multiple `defineAuth` calls are not allowed within an Amplify backend',
157-
resolution: 'Remove all but one `defineAuth` call',
156+
'Multiple `defineAuth` or `referenceAuth` calls are not allowed within an Amplify backend',
157+
resolution: 'Remove all but one `defineAuth` or `referenceAuth` call',
158158
})
159159
);
160160
});

packages/backend-auth/src/factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ export class AmplifyAuthFactory implements ConstructFactory<BackendAuth> {
103103
if (AmplifyAuthFactory.factoryCount > 0) {
104104
throw new AmplifyUserError('MultipleSingletonResourcesError', {
105105
message:
106-
'Multiple `defineAuth` calls are not allowed within an Amplify backend',
107-
resolution: 'Remove all but one `defineAuth` call',
106+
'Multiple `defineAuth` or `referenceAuth` calls are not allowed within an Amplify backend',
107+
resolution: 'Remove all but one `defineAuth` or `referenceAuth` call',
108108
});
109109
}
110110
AmplifyAuthFactory.factoryCount++;

0 commit comments

Comments
 (0)