Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/next-release/main' into move-a…
Browse files Browse the repository at this point in the history
…uth-pages
  • Loading branch information
josefaidt committed May 2, 2024
2 parents 15962a8 + 406d1ca commit 48f4960
Show file tree
Hide file tree
Showing 25 changed files with 253 additions and 184 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
/src/themes @aws-amplify/documentation-team
/src/utils @aws-amplify/documentation-team
/tasks @aws-amplify/documentation-team
.github @aws-amplify/documentation-team

#Protected Content
/src/protected @reesscot @srquinn21 @Milan-Shah @swaminator
38 changes: 38 additions & 0 deletions .github/workflows/check_for_console_errors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CheckConsoleErrors
on:
pull_request:
branches: [main]
types: [opened, synchronize]
permissions:
contents: read
jobs:
CheckConsoleErrors:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2 https://github.com/actions/checkout/commit/b4ffde65f46336ab88eb53be808477a3936bae11
- name: Setup Node.js 20.x
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3.7.0 https://github.com/actions/setup-node/commit/e33196f7422957bea03ed53f6fbb155025ffc7b8
with:
node-version: 20.x
- name: Install Dependencies
run: yarn
- name: Run Build
run: yarn build:release
env:
NODE_OPTIONS: --max_old_space_size=4096
- name: Run Server
run: |
python -m http.server 3000 -d ${{ vars.BUILD_DIR }} &
sleep 5
- name: Run Console Errors
id: consoleErrors
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1 https://github.com/actions/github-script/commit/d7906e4ad0b1822421a7e6a35d5ca353c962f410
with:
result-encoding: string
script: |
const { consoleErrors } = require('./tasks/console-errors.js');
return await consoleErrors();
- name: Fail if console errors have been found
if: ${{ steps.consoleErrors.outputs.result }}
run: exit 1
2 changes: 1 addition & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,7 @@
"privatesaccess",
"menudetaileditors",
"editorgroupaccess",
"publicauthreadonly",
"authreadonly",
"envs",
"Onetoone",
"onetomany",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
"@adobe/css-tools": "4.3.2",
"follow-redirects": "^1.15.6",
"ip": "2.0.1",
"sharp": "0.32.6"
"sharp": "0.32.6",
"ejs": "3.1.10"
},
"scripts": {
"clean": "rm -rf node_modules yarn.lock",
Expand Down
File renamed without changes
8 changes: 4 additions & 4 deletions src/components/BlockSwitcher/__tests__/BlockSwitcher.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ describe('BlockSwitcher', () => {
const blockSwitcher = await screen.findByText(blockAContent);
expect(blockSwitcher).toBeInTheDocument();
});

it('should have more than one Block', async () => {
render(component);
expect(component.props.children.length).toBeGreaterThan(1);
});

it('should show the first Block as default', async () => {
render(component);
const tabs = await screen.getAllByRole('tab');
Expand All @@ -39,7 +39,7 @@ describe('BlockSwitcher', () => {
expect(panels[1]).not.toHaveClass('amplify-tabs__panel--active');
expect(panels[2]).not.toHaveClass('amplify-tabs__panel--active');
});

it('should load all Blocks to the DOM', async () => {
render(component);
const blockA = await screen.findByText(blockAContent);
Expand All @@ -49,7 +49,7 @@ describe('BlockSwitcher', () => {
expect(blockB).toBeInTheDocument();
expect(blockC).toBeInTheDocument();
});

it('should switch tabs upon click', async () => {
render(component);
const tabs = await screen.getAllByRole('tab');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ export const meta = {
'Use Amazon Cognito Auth plugin to sign in a user into Amazon Cognito User Pool using user defined custom flow',
platforms: [
'android',
// 'angular',
'flutter',
// 'javascript',
// 'nextjs',
// 'react',
// 'react-native',
'swift',
// 'vue'
],
};

Expand Down Expand Up @@ -41,7 +35,7 @@ An application with Amplify libraries integrated and a minimum target of any of
- **watchOS 9.0**, using **Xcode 14.3** or later.
- **visionOS 1.0**, using **Xcode 15 beta 2** or later. (Preview support - see below for more details.)

For a full example, please follow the [project setup walkthrough](/[platform]/start/project-setup/prerequisites/).
For a full example, please follow the [project setup walkthrough](/[platform]/start/quickstart/).

<Callout>

Expand All @@ -66,7 +60,7 @@ For more information on adding capabilities to your application, see [Xcode Capa

The custom auth flow can be [configured manually](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-challenge.html).

If you have already configured custom auth, you can use the custom auth flow by changing the `authenticationFlowType` value in your [Amplify configuration](/[platform]/build-a-backend/auth/existing-resources/) to `CUSTOM_AUTH`.
If you have already configured custom auth, you can use the custom auth flow by changing the `authenticationFlowType` value in your Amplify configuration to `CUSTOM_AUTH`. For more information on authentication flow types, you can check out the [Cognito documentation](https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-authentication-flow.html).

## Register a user

Expand Down Expand Up @@ -244,7 +238,7 @@ Since this is a custom authentication flow with a challenge, the result of the s

## Confirm sign in with custom challenge

Get the custom challenge (`1234` in this case) from the user and pass it to the `confirmSignin()` api.
To get a custom challenge from the user, create an appropriate UI for the user to submit the required value, and pass that value into the `confirmSignin()` API.

<BlockSwitcher>

Expand Down Expand Up @@ -294,9 +288,9 @@ Confirm sign in succeeded

### Lambda Trigger Setup

AWS Amplify now supports creating functions as part of its new backend experience. For more information on the Functions and how to start with them check out [Functions documentation](/[platform]/build-a-backend/functions/). In addition, more information on available triggers can be found in the [Cognito documentation](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-challenge.html).
AWS Amplify now supports creating functions as part of its new backend experience. For more information on the Functions and how to start with them check out [Functions documentation](/[platform]/build-a-backend/functions/). In addition, more information on available triggers can be found in the [Cognito documentation](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html).

### Custom Auth Flow with SRP
### Custom Auth Flow with Secure Remote Password (SRP)

Cognito User Pool allows to start the custom authentication flow with SRP as the first step. If you would like to use this flow, setup Define Auth Lambda trigger to handle SRP_A as the first challenge as shown below:

Expand Down Expand Up @@ -337,78 +331,20 @@ let signInResult = try await Amplify.Auth.signIn(
options: .init(pluginOptions: options))
```

### CAPTCHA-based authentication

Here is the sample for creating a CAPTCHA challenge with a Lambda Trigger.

The `Create Auth Challenge Lambda Trigger` creates a CAPTCHA as a challenge to the user. The URL for the CAPTCHA image and the expected answer is added to the private challenge parameters:

```javascript
export const handler = async (event) => {
if (!event.request.session || event.request.session.length === 0) {
event.response.publicChallengeParameters = {
captchaUrl: <captcha url>,
};
event.response.privateChallengeParameters = {
answer: <expected answer>,
};
event.response.challengeMetadata = "CAPTCHA_CHALLENGE";
}
return event;
};
```

This `Define Auth Challenge Lambda Trigger` defines a custom challenge:

```javascript
export const handler = async (event) => {
if (!event.request.session || event.request.session.length === 0) {
// If we don't have a session or it is empty then send a CUSTOM_CHALLENGE
event.response.challengeName = "CUSTOM_CHALLENGE";
event.response.failAuthentication = false;
event.response.issueTokens = false;
} else if (event.request.session.length === 1 && event.request.session[0].challengeResult === true) {
// If we passed the CUSTOM_CHALLENGE then issue token
event.response.failAuthentication = false;
event.response.issueTokens = true;
} else {
// Something is wrong. Fail authentication
event.response.failAuthentication = true;
event.response.issueTokens = false;
}

return event;
};
```

The `Verify Auth Challenge Response Lambda Trigger` is used to verify a challenge answer:

```javascript
export const handler = async (event, context) => {
if (event.request.privateChallengeParameters.answer === event.request.challengeAnswer) {
event.response.answerCorrect = true;
} else {
event.response.answerCorrect = false;
}

return event;
};
```

</InlineFilter>
<InlineFilter filters={['android']}>
The Auth category can be configured to perform a [custom authentication flow](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-challenge.html) defined by you. The following guide shows how to setup a simple passwordless authentication flow.

## Prerequisites

* An Android application targeting at least Android SDK API level 24 with Amplify libraries integrated
* For a full example of creating Android project, please follow the [project setup walkthrough](/[platform]/start/project-setup/create-application/)
* For a full example of creating Android project, please follow the [project setup walkthrough](/[platform]/start/quickstart/)

## Configure Auth

The custom auth flow can be [configured manually](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-challenge.html).

If you have already configured custom auth, you can use the custom auth flow by changing the `authenticationFlowType` value in your [Amplify configuration](/[platform]/build-a-backend/auth/existing-resources/) to `CUSTOM_AUTH`.
If you have already configured custom auth, you can use the custom auth flow by changing the `authenticationFlowType` value in your Amplify configuration to `CUSTOM_AUTH`. For more information on authentication flow types, you can check out the [Cognito documentation](https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-authentication-flow.html).

## Register a user

Expand Down Expand Up @@ -683,9 +619,9 @@ Confirm sign in succeeded

### Lambda Trigger Setup

AWS Amplify now supports creating functions as part of the AWS Amplify. For more information on the Functions and how to start with them check out [Functions documentation](/[platform]/build-a-backend/functions/). In addition, more information on available triggers can be found in the [Cognito documentation](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-challenge.html).
AWS Amplify now supports creating functions as part of the AWS Amplify. For more information on the Functions and how to start with them check out [Functions documentation](/[platform]/build-a-backend/functions/). In addition, more information on available triggers can be found in the [Cognito documentation](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html).

### Custom Auth Flow with SRP
### Custom Auth Flow with Secure Remote Password (SRP)

Cognito User Pool allows to start the custom authentication flow with SRP as the first step. If you would like to use this flow, setup Define Auth Lambda trigger to handle SRP_A as the first challenge as shown below:

Expand Down Expand Up @@ -793,64 +729,6 @@ RxAmplify.Auth.signIn("username", "password", options)
</Block>
</BlockSwitcher>

### CAPTCHA-based authentication

Here is the sample for creating a CAPTCHA challenge with a Lambda Trigger.

The `Create Auth Challenge Lambda Trigger` creates a CAPTCHA as a challenge to the user. The URL for the CAPTCHA image and the expected answer are added to the private challenge parameters:

```javascript
export const handler = async (event) => {
if (!event.request.session || event.request.session.length === 0) {
event.response.publicChallengeParameters = {
captchaUrl: <captcha url>,
};
event.response.privateChallengeParameters = {
answer: <expected answer>,
};
event.response.challengeMetadata = "CAPTCHA_CHALLENGE";
}
return event;
};
```

This `Define Auth Challenge Lambda Trigger` defines a custom challenge:

```javascript
export const handler = async (event) => {
if (!event.request.session || event.request.session.length === 0) {
// If we don't have a session or it is empty then send a CUSTOM_CHALLENGE
event.response.challengeName = "CUSTOM_CHALLENGE";
event.response.failAuthentication = false;
event.response.issueTokens = false;
} else if (event.request.session.length === 1 && event.request.session[0].challengeResult === true) {
// If we passed the CUSTOM_CHALLENGE then issue token
event.response.failAuthentication = false;
event.response.issueTokens = true;
} else {
// Something is wrong. Fail authentication
event.response.failAuthentication = true;
event.response.issueTokens = false;
}

return event;
};
```

The `Verify Auth Challenge Response Lambda Trigger` is used to verify a challenge answer:

```javascript
export const handler = async (event, context) => {
if (event.request.privateChallengeParameters.answer === event.request.challengeAnswer) {
event.response.answerCorrect = true;
} else {
event.response.answerCorrect = false;
}

return event;
};
```

</InlineFilter>

<InlineFilter filters={['flutter']}>
Expand All @@ -859,13 +737,13 @@ The Auth category can be configured to perform a [custom authentication flow](ht
## Prerequisites
A Flutter application targeting Flutter SDK >= 3.3.0 with Amplify libraries integrated.

Amplify requires a minimum target platform for iOS (13.0), Android (API level 24), and macOS (10.15). Additional setup is required for some target platforms. Please see the [platform setup](/[platform]/start/project-setup/platform-setup/) guide for more details on platform specific setup.
Amplify requires a minimum target platform for iOS (13.0), Android (API level 24), and macOS (10.15). Additional setup is required for some target platforms. Please see the [platform setup](/[platform]/build-a-backend/auth/connect-your-frontend/sign-in/#platform-setup) for more details on platform specific setup.

## Configure Auth

The custom auth flow can be [configured manually](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-challenge.html).

If you have already configured custom auth, you can use the custom auth flow by changing the `authenticationFlowType` value in your [Amplify configuration](/[platform]/build-a-backend/auth/existing-resources/) to `CUSTOM_AUTH`.
If you have already configured custom auth, you can use the custom auth flow by changing the `authenticationFlowType` value in your Amplify configuration to `CUSTOM_AUTH`. For more information on authentication flow types, you can check out the [Cognito documentation](https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-authentication-flow.html).

## Register a user

Expand Down Expand Up @@ -946,7 +824,7 @@ user has already signed in and a valid session is active. You must first call
</Callout>
## Confirm sign in with custom challenge

Get the custom challenge (`1234` in this case) from the user and pass it to the `confirmSignin()` api.
To get a custom challenge from the user, create an appropriate UI for the user to submit the required value, and pass that value into the `confirmSignin()` API.

```dart
Future<void> confirmSignIn(String generatedNumber) async {
Expand Down Expand Up @@ -977,7 +855,7 @@ Exception: `NotAuthorizedException` with a message `Invalid session for the user

The example in this documentation demonstrates the passwordless custom authentication flow. However, it is also possible to require that users supply a valid password as part of the custom authentication flow.

To require a valid password, you can alter the `DefineAuthChallenge` code to handle a `PASSWORD_VERIFIER` step:
To require a valid password, you can alter the [DefineAuthChallenge](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-define-auth-challenge.html) code to handle a `PASSWORD_VERIFIER` step:

```js
exports.handler = async (event) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ npx ampx sandbox

</InlineFilter>

After a successful deployment, this command also generates a configuration file (`amplify_outputs.json`) to enable your frontend app to connect to your backend resources. The values you configure in your backend authentication resource are set in the generated configuration file to automatically configure the frontend [`Authenticator connected component`](https://ui.docs.amplify.aws/react/connected-components/authenticator).
After a successful deployment, this command also generates an outputs file (`amplify_outputs.json`) to enable your frontend app to connect to your backend resources. The values you configure in your backend authentication resource are set in the generated outputs file to automatically configure the frontend [`Authenticator connected component`](https://ui.docs.amplify.aws/react/connected-components/authenticator).

## Connect your application code to your auth resource

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ npx ampx sandbox --outputs-format dart --outputs-out-dir lib

## Connect your application code to the data backend

Once the cloud sandbox is up and running, it will also create an `amplifyconfiguration.json` file, which includes the relevant connection information to your data backend, like your API endpoint URL and API key.
Once the cloud sandbox is up and running, it will also create an `amplify_outputs.json` file, which includes the relevant connection information to your data backend, like your API endpoint URL and API key.

To connect your frontend code to your backend, you need to:

1. configure the Amplify library with the Amplify client configuration file
1. configure the Amplify library with the Amplify client configuration file (`amplify_outputs.json`)
2. generate a new API client from the Amplify library
3. make an API request with end-to-end type-safety

Expand All @@ -133,9 +133,9 @@ In your app's entry point, typically **main.tsx** for React apps created using V

```tsx title="src/main.tsx"
import { Amplify } from 'aws-amplify';
import config from '../amplifyconfiguration.json';
import outputs from '../amplify_outputs.json';

Amplify.configure(config);
Amplify.configure(outputs);
```

</InlineFilter>
Expand Down
Loading

0 comments on commit 48f4960

Please sign in to comment.