openspec: archive fix-cognito-signin, sync specs
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -8,16 +8,46 @@ The integration SHALL provide an async API client class (`PerfectDraftApiClient`
|
||||
- **THEN** it SHALL store the session and set the base URL to `https://api.perfectdraft.com`
|
||||
|
||||
### Requirement: Sign-in with reCAPTCHA token
|
||||
The client SHALL authenticate by POSTing to `/authentication/sign-in` with email, password, recaptchaToken, and recaptchaAction fields. The `x-api-key` SHALL be sent as a header. The `recaptchaAction` SHALL be `Magento/login`.
|
||||
The client SHALL authenticate by calling AWS Cognito `InitiateAuth` at `https://cognito-idp.eu-west-1.amazonaws.com/` with `AuthFlow: USER_PASSWORD_AUTH`, the Cognito client ID, and the email and password as `USERNAME` and `PASSWORD`. `ClientMetadata` SHALL carry `recaptchaToken`, `recaptchaAction: Magento/login`, and `domain: https://www.perfectdraft.com`, all three of which PerfectDraft's PreAuthentication check requires. The client SHALL NOT sign in through `api.perfectdraft.com/authentication/sign-in`, which does not forward `domain`.
|
||||
|
||||
#### Scenario: Successful sign-in
|
||||
- **WHEN** the client calls `authenticate(email, password, recaptcha_token)`
|
||||
- **THEN** it SHALL POST to `/authentication/sign-in` with the correct payload and `x-api-key` header
|
||||
- **THEN** it SHALL store the returned `AccessToken`, `IdToken`, and `RefreshToken`
|
||||
- **THEN** it SHALL POST an `InitiateAuth` request to Cognito with `Content-Type: application/x-amz-json-1.1` and `X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth`
|
||||
- **THEN** the request SHALL carry the `ClientMetadata` fields listed above
|
||||
- **THEN** it SHALL parse the response with `content_type=None` to accept `application/x-amz-json-1.1`
|
||||
- **THEN** it SHALL store the `AccessToken`, `IdToken`, and `RefreshToken` from `AuthenticationResult`
|
||||
|
||||
#### Scenario: Challenge instead of tokens
|
||||
- **WHEN** Cognito answers 200 without a complete `AuthenticationResult`, for example with a `ChallengeName`
|
||||
- **THEN** the client SHALL raise `AuthenticationError`, carrying the challenge name as its error type when present
|
||||
- **THEN** no stored token SHALL change
|
||||
|
||||
#### Scenario: Sign-in failure
|
||||
- **WHEN** the API returns 400, 401, or 403
|
||||
- **WHEN** Cognito returns 400, 401, or 403
|
||||
- **THEN** the client SHALL raise `AuthenticationError` with the status and response body
|
||||
- **THEN** the error SHALL expose the Cognito error type (`__type`, without any namespace prefix) and the human-readable message, when the body supplies them
|
||||
|
||||
#### Scenario: Rejection is classified
|
||||
- **WHEN** a sign-in is rejected with error type `NotAuthorizedException` or `UserNotFoundException`
|
||||
- **THEN** the error SHALL classify as a credentials failure
|
||||
- **WHEN** a sign-in is rejected with error type `UserLambdaValidationException`
|
||||
- **THEN** the error SHALL classify as a verification token failure
|
||||
- **WHEN** a sign-in is rejected with any other error type, or none
|
||||
- **THEN** the error SHALL classify as an other failure
|
||||
|
||||
#### Scenario: Unreadable rejection body
|
||||
- **WHEN** a rejection body is not JSON, such as an HTML error page
|
||||
- **THEN** the client SHALL still raise `AuthenticationError`, with no error type and a reason truncated to at most 200 characters
|
||||
|
||||
#### Scenario: Other sign-in failures
|
||||
- **WHEN** Cognito returns any other non-200 status
|
||||
- **THEN** the client SHALL raise `PerfectDraftApiError`
|
||||
- **WHEN** the request fails due to `aiohttp.ClientError`
|
||||
- **THEN** the client SHALL raise `PerfectDraftConnectionError`
|
||||
|
||||
#### Scenario: Secrets are not logged
|
||||
- **WHEN** sign-in succeeds or fails
|
||||
- **THEN** the password, the verification token, and the issued tokens SHALL NOT be logged
|
||||
|
||||
### Requirement: Token refresh via Cognito
|
||||
The client SHALL refresh expired access tokens by calling AWS Cognito directly at `https://cognito-idp.eu-west-1.amazonaws.com/`, bypassing the API gateway and reCAPTCHA. The Cognito client ID is `57ddq2ppqg2jcpup06r2g1deur`.
|
||||
|
||||
@@ -9,7 +9,7 @@ The config flow SHALL present a form requesting the user's PerfectDraft account
|
||||
- **THEN** submitting SHALL advance to the token step
|
||||
|
||||
### Requirement: Token step collects verification token
|
||||
The config flow SHALL present a form requesting a reCAPTCHA verification token as the second step, with instructions linking to the README.
|
||||
The config flow SHALL present a form requesting a reCAPTCHA verification token as the second step, with instructions linking to the README. When authentication fails, the flow SHALL tell the user which input was rejected and show the server's reason.
|
||||
|
||||
#### Scenario: Token step display
|
||||
- **WHEN** the user reaches the token step
|
||||
@@ -24,8 +24,24 @@ The config flow SHALL present a form requesting a reCAPTCHA verification token a
|
||||
- **THEN** it SHALL create a config entry storing email, access token, ID token, refresh token, and machine ID
|
||||
|
||||
#### Scenario: Invalid or expired token
|
||||
- **WHEN** authentication fails
|
||||
- **THEN** the flow SHALL show an error and allow the user to retry with a fresh token
|
||||
- **WHEN** authentication fails as a verification token failure
|
||||
- **THEN** the flow SHALL show the token form again with the `token_rejected` error, including the server's reason
|
||||
- **THEN** the user SHALL be able to retry with a fresh token
|
||||
|
||||
#### Scenario: Wrong email or password
|
||||
- **WHEN** authentication fails as a credentials failure
|
||||
- **THEN** the flow SHALL show the credentials form again with the `invalid_credentials` error, including the server's reason
|
||||
- **THEN** that form SHALL be the email and password form during setup, and the `reauth_confirm` form during reauth
|
||||
- **THEN** after the user resubmits credentials, the flow SHALL ask for a fresh token
|
||||
|
||||
#### Scenario: Other authentication failure
|
||||
- **WHEN** authentication fails for any other reason
|
||||
- **THEN** the flow SHALL show the token form again with the `invalid_auth` error, including the server's reason
|
||||
- **THEN** the user SHALL be able to retry with a fresh token
|
||||
|
||||
#### Scenario: Failure without a server reason
|
||||
- **WHEN** authentication fails and the server supplied no reason
|
||||
- **THEN** the error message SHALL still render, with a fixed fallback in place of the reason and no unfilled placeholder
|
||||
|
||||
#### Scenario: API unreachable
|
||||
- **WHEN** the API is unreachable
|
||||
@@ -78,8 +94,8 @@ The integration SHALL support Home Assistant's reauth mechanism when the refresh
|
||||
- **THEN** the flow SHALL treat it as the same account and complete successfully
|
||||
|
||||
#### Scenario: Reauth authentication fails
|
||||
- **WHEN** the verification token is expired or the credentials are wrong during reauth
|
||||
- **THEN** the flow SHALL show the `invalid_auth` error on the token form and allow retry with a fresh token
|
||||
- **WHEN** the verification token or the credentials are rejected during reauth
|
||||
- **THEN** the flow SHALL show the same error, on the same form, as the matching failure during setup (`token_rejected`, `invalid_credentials` on the `reauth_confirm` form, or `invalid_auth`)
|
||||
- **THEN** the existing config entry's tokens SHALL be left unchanged
|
||||
|
||||
#### Scenario: Machine ID lookup is skipped when already known
|
||||
|
||||
Reference in New Issue
Block a user