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

Not getting correct error message from Google signin. #3176

Closed
AmbrishPatel94 opened this issue Aug 25, 2023 · 13 comments
Closed

Not getting correct error message from Google signin. #3176

AmbrishPatel94 opened this issue Aug 25, 2023 · 13 comments
Assignees
Labels
auth Issues related to the Auth category bug Something isn't working

Comments

@AmbrishPatel94
Copy link

Describe the bug

I am use following Amplify version 2.0.0-Next Major, I register new user on amplify and try to login with amplify google signin "Amplify.Auth.signInWithWebUI(for: .google, presentationAnchor: presentationAnchor, options: .preferPrivateSession())" with same user then that time i got error response "invaid_request". But i need to get response like this "invalid_request: PreSignUp failed with error {"error":{"code":409,"custom_code":"002","message":"U2FsdGVkX19xJYJt/Dckptj0KKXuBfrD3uhZScr1bBvqYF2Q29iGb7iC16MDCwLwbIVs1tNcaHQreEIopKwg9onymeCveyiCwHNzjpmPciQ3XSiQ7Oi+pVW4KyB5lUXC"}}."

Steps To Reproduce

I register new user on amplify and try to login with amplify google signin "Amplify.Auth.signInWithWebUI(for: .google, presentationAnchor: presentationAnchor, options: .preferPrivateSession())" with same user then that time i got error response "invaid_request".

Expected behavior

I need to get response like this "invalid_request: PreSignUp failed with error {"error":{"code":409,"custom_code":"002","message":"U2FsdGVkX19xJYJt/Dckptj0KKXuBfrD3uhZScr1bBvqYF2Q29iGb7iC16MDCwLwbIVs1tNcaHQreEIopKwg9onymeCveyiCwHNzjpmPciQ3XSiQ7Oi+pVW4KyB5lUXC"}}."

Amplify Framework Version

2.0.0-Next Major

Amplify Categories

Auth

Dependency manager

Swift PM

Swift version

5

CLI version

10.6.1

Xcode version

14.2

Relevant log output

<details>
<summary>Log Messages</summary>


INSERT LOG MESSAGES HERE
```

Is this a regression?

Yes

Regression additional context

No response

Platforms

iOS

OS Version

13.0

Device

iphone 13

Specific to simulators

No response

Additional context

No response

@atierian atierian self-assigned this Aug 25, 2023
@atierian atierian added auth Issues related to the Auth category question General question labels Aug 25, 2023
@atierian
Copy link
Member

Hey @AmbrishPatel94, thanks for opening this issue.
If I understand correctly, you're receiving an error with only invalid_request but are expecting an error with more information like in the example you provided:

"invalid_request: PreSignUp failed with error {"error":{"code":409,"custom_code":"002","message":"U2FsdGVkX19xJYJt/Dckptj0KKXuBfrD3uhZScr1bBvqYF2Q29iGb7iC16MDCwLwbIVs1tNcaHQreEIopKwg9onymeCveyiCwHNzjpmPciQ3XSiQ7Oi+pVW4KyB5lUXC"}}."

Can you please provide a full code example of how you're catching that error?

@atierian atierian added the pending-community-response Issue is pending response from the issue requestor label Aug 25, 2023
@AmbrishPatel94
Copy link
Author

Hi Atierian, thanks for reaching out us.

I am using this
Task{
do {
let signInResult = try await Amplify.Auth.signInWithWebUI(for: .google, presentationAnchor: self.view.window!, options: .preferPrivateSession())

            if signInResult.isSignedIn {
                print("Sign in succeeded")
            }else{
                
            }
        } catch let error as AuthError {
            print("Sign in failed \(error )")
        // here i am receiving error message invalid_request

        } catch {

            print("Unexpected error: \(error)")


        }
    }

@AmbrishPatel94
Copy link
Author

Hi Atierian, thanks for reaching out us.

I am using this Task{ do { let signInResult = try await Amplify.Auth.signInWithWebUI(for: .google, presentationAnchor: self.view.window!, options: .preferPrivateSession())

            if signInResult.isSignedIn {
                print("Sign in succeeded")
            }else{
                
            }
        } catch let error as AuthError {
            print("Sign in failed \(error )")
        // here i am receiving error message invalid_request

        } catch {

            print("Unexpected error: \(error)")


        }
    }

@github-actions github-actions bot removed the pending-community-response Issue is pending response from the issue requestor label Aug 28, 2023
@AmbrishPatel94
Copy link
Author

Hi Atierian,

I am waiting to your response.

@atierian
Copy link
Member

It looks like you accidentally closed the issue, so I'm reopening it.

Thanks for the callsite example. You mentioned that you're receiving the error message in this catch let error as AuthError block. Please paste the full content of the error message printed there. Based on the code block you provided, there should be more that just invalid_request.

catch let error as AuthError {
    print("Sign in failed \(error )")
    // here i am receiving error message invalid_request
}

@atierian atierian reopened this Aug 28, 2023
@atierian atierian added the pending-community-response Issue is pending response from the issue requestor label Aug 28, 2023
@AmbrishPatel94
Copy link
Author

Thanks for your reply

Here i am receiving this error message

▿ 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

@atierian
Copy link
Member

Thanks, that's helpful. A few more questions:

  • Which version of Amplify are you using? You mentioned that you're using 2.0.0-Next-Major; please specify the exact version you're encountering this on. You can see the in Xcode > Project Navigator > Package Dependencies.
  • Why do you expect the more verbose error / where is it coming from? Are you using a PreSignUp_ExternalProvider lambda trigger here?

Any details would be helpful here. Thanks!

@AmbrishPatel94
Copy link
Author

I am using Amplify version 2.15.4 yes we are using a PreSignUp_ExternalProvider lambda trigger here.

@atierian
Copy link
Member

Thanks.

The error that you're expecting to receive:

invalid_request: PreSignUp failed with error {"error":{"code":409,"custom_code":"002","message":"U2FsdGVkX19xJYJt/Dckptj0KKXuBfrD3uhZScr1bBvqYF2Q29iGb7iC16MDCwLwbIVs1tNcaHQreEIopKwg9onymeCveyiCwHNzjpmPciQ3XSiQ7Oi+pVW4KyB5lUXC"}}.

Are you providing this whole error to Cognito in your PreSignUp_ExternalProvider triggered lambda?

If so, can you please paste the error handling portion of the lambda here?

@AmbrishPatel94
Copy link
Author

We are using this for PreSignUp_ExternalProvider

if (event.triggerSource === "PreSignUp_ExternalProvider") { console.log( Identified :: This call is for external service provider. But, its duplicated flow so we need to stop account creation & send error message 409 with 002.`
);

            // If count of duplicationData is 1 then we link the accounts & stop account creation with 409 / 002 else we stop account creation with 409 / 001 so chooser window can be shown on FE
            if (duplicationData.Users.length === 1) {
                console.log(
                    `The count is exactly 1 so we need to link the account & create 409 with 002 situation.`
                );

                let attributes = duplicationData.Users[0].Attributes;
                let GUID = attributes.find(
                    (attribute) => attribute["Name"] === "sub"
                )["Value"];

                console.log(
                    `This is the GUID from attributes - ${GUID} | Now, Attempting to link the provider account :: `
                );

                await linkProviderAccount(
                    duplicationData.Users[0].Username,
                    event.userName
                );
                console.log(`Now, Attempting to update the email_verified : true inside the cognito :: `);
                await updateUserInCognito(duplicationData.Users[0].Username);
                console.log(
                    `Now, Attempting to generate the authcode using the generateAuthCode fn from the layer :: `
                );
                let message = await generateAuthCode(GUID);

                console.log(`Now, Attempting to encrypt the authcode :: `);
                let AuthToken = await encrypt(
                    Buffer.from(message, "utf-8")
                );

                console.log(
                    `Now, Attempting to store the authcode in dynamoDB :: `
                );
                await storeAuthToken(GUID, AuthToken);

                // Importing the checkUsernameType function from helper in this file & sending this as a param to this function so it can be used there as well.
                let duplicateAccounts = await generateDuplicateAccounts(
                    checkUsernameType,
                    duplicationData
                );
                let encryptedDuplicateAccounts = await encryptData(
                    JSON.stringify(duplicateAccounts)
                );

                // Passwordless sign-in attempt
                let errorResponseData = await errorResponse(
                    "409",
                    "002",
                    encryptedDuplicateAccounts
                );
                callback(new Error(errorResponseData), event);

                console.log(
                    `/Safely exiting the scenario :: 409 with 002 | Stopping the account creation`
                );
                return;
            }`

@atierian
Copy link
Member

Great, thanks.
It looks like this is because we're extracting the error query parameter, but not the error_description.

Could you try out the branch hostedui_errordescription and see if that resolves your issue?

@AmbrishPatel94
Copy link
Author

HI Atierian,
Thanks for get solution.
But my question is, How can i use this code because i a using this sdk by Package dependency and there are no option to edit.
Can you add this code on new version?

@atierian
Copy link
Member

atierian commented Aug 30, 2023

This fix was included in Amplify Swift v2.16.1
If you're still using the version rule Up to Next Major 2.0.0, you can select File > Packages > Update to Latest Package Versions to update to 2.16.1.

Please let us know whether this new version resolves your issue. Thanks again for reporting it!

@atierian atierian added bug Something isn't working closing soon This issue will be closed in 7 days unless further comments are made. and removed pending-community-response Issue is pending response from the issue requestor question General question closing soon This issue will be closed in 7 days unless further comments are made. labels Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth Issues related to the Auth category bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants