Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auth): hostedui extract error_description query pararm #3183

Merged
merged 3 commits into from
Aug 30, 2023

Conversation

atierian
Copy link
Member

@atierian atierian commented Aug 28, 2023

Issue #

Description

If an error query parameter is included in the HostedUI callback, we currently throw a .service error with the value of the error key, omitting important information that may be needed by the caller. With this change, we now attempt to extract and use the value from error_description; if it doesn't exist, we fall back to the error we know is there. The fall back to error is necessary because error_description is optional according to the spec.

This change brings Amplify Swift in parity with Android, Flutter, and JS.

In the linked issue, we can see a specific use case the current behavior is blocking - client side logic based on information contained in an error thrown by a PreSignUp_ExternalProvider Lambda trigger. [Service Documentation]

Testing

In addition to the added test cases, this change was manually tested with a PreSignUp Lambda trigger:

exports.handler = (event, context, callback) => {
    const payload = JSON.stringify(
        { code: "409", custom_code: "002", message: "<placeholder>" }
    );
    const error = Error(payload);
    callback(error, event);
};

and the following client side code:

do {
    _ = try await Amplify.Auth.signInWithWebUI(
        for: .google, // this can be any social provider
        presentationAnchor: window
    )
} catch let error as AuthError {
>> breakpoint
} catch {
    print("Unexpected error: \(error)")
}

Breaking in the first catch block and po'ing the error -

Targeting v2.16.0 (current latest release), we see:

(lldb) po error
▿ AuthError: invalid_request
Recovery suggestion: Received an error message from the service
  ▿ service : 3 elements
    - .0 : "invalid_request"
    - .1 : "Received an error message from the service"
    - .2 : nil

Targeting branch hostedui_errordescription, we see:

(lldb) po error
▿ AuthError: invalid_request PreSignUp+failed+with+error+{"code":"409","custom_code":"002","message":"<placeholder>"}.+
Recovery suggestion: Received an error message from the service
  ▿ service : 3 elements
    - .0 : "invalid_request PreSignUp+failed+with+error+{\"code\":\"409\",\"custom_code\":\"002\",\"message\":\"<placeholder>\"}.+"
    - .1 : "Received an error message from the service"
    - .2 : nil

General Checklist

  • Added new tests to cover change, if needed
  • Build succeeds with all target using Swift Package Manager
  • All unit tests pass
  • All integration tests pass
  • Security oriented best practices and standards are followed (e.g. using input sanitization, principle of least privilege, etc)
  • Documentation update for the change if required
  • PR title conforms to conventional commit style
  • New or updated tests include Given When Then inline code documentation and are named accordingly testThing_condition_expectation()
  • If breaking change, documentation/changelog update with migration instructions

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@atierian atierian temporarily deployed to Fortify August 29, 2023 18:14 — with GitHub Actions Inactive
@atierian atierian temporarily deployed to Fortify August 29, 2023 18:20 — with GitHub Actions Inactive
@atierian atierian marked this pull request as ready for review August 29, 2023 18:20
@atierian atierian requested a review from a team as a code owner August 29, 2023 18:20
@codecov-commenter
Copy link

Codecov Report

Merging #3183 (a124bd5) into main (9d6fa8b) will increase coverage by 13.55%.
Report is 21 commits behind head on main.
The diff coverage is 0.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@             Coverage Diff             @@
##             main    #3183       +/-   ##
===========================================
+ Coverage   50.61%   64.17%   +13.55%     
===========================================
  Files         385     1067      +682     
  Lines        7203    36132    +28929     
===========================================
+ Hits         3646    23186    +19540     
- Misses       3557    12946     +9389     
Flag Coverage Δ
API_plugin_unit_test 66.52% <ø> (?)
AWSPluginsCore 69.55% <ø> (?)
Amplify 48.01% <ø> (-0.02%) ⬇️
Analytics_plugin_unit_test 86.39% <ø> (?)
Auth_plugin_unit_test 74.54% <0.00%> (?)
CoreMLPredictions_plugin_unit_test 59.44% <ø> (?)
DataStore_plugin_unit_test 80.09% <ø> (?)
Geo_plugin_unit_test 54.06% <ø> (?)
Logging_plugin_unit_test 62.61% <ø> (ø)
Predictions_plugin_unit_test 35.17% <ø> (?)
PushNotifications_plugin_unit_test 69.43% <ø> (ø)
Storage_plugin_unit_test 54.10% <ø> (?)
unit_tests 64.17% <0.00%> (+13.55%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
.../HostedUI/HostedUIASWebAuthenticationSession.swift 0.00% <0.00%> (ø)

... and 682 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@harsh62 harsh62 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@atierian atierian merged commit 8bbf5c7 into main Aug 30, 2023
@atierian atierian deleted the hostedui_errordescription branch August 30, 2023 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants