amazon-archives / amazon-cognito-auth-js

The Amazon Cognito Auth SDK for JavaScript simplifies adding sign-up, sign-in with user profile functionality to web apps.
Apache License 2.0
424 stars 232 forks source link

DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded. #87

Open iamcootis opened 6 years ago

iamcootis commented 6 years ago

I am getting this error when attempting to login using Facebook. The error is thrown from line 165 in the example code. It works fine when logging in using Google or Cognito. Any ideas?

rdpacheco commented 5 years ago

Getting this as well

rdpacheco commented 5 years ago

@iamcootis I stepped through the AWS code and it was a VueJS issue. Cognito was redirecting to a Vue app that auto-added a trailing slash. So my access token in the url turned from domain.com/#access-token=... to domain.com/#/access-token=.... This messed with the SDK parsing.

I hope you find your solution as well.

brachi-wernick commented 5 years ago

I'm also getting this, when using HashRouter (react-router-dom) to navigate. seems like it dosn't matter where the '#' appears in URL. @rdpacheco can you please clarify how did you fix this? what is the correct place of the '#'?

error is:

VM200:37 Error in getting provisions DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
    at CognitoAccessToken.getUsername (https://localhost:1234/src.74b10521.js:57682:23)
    at CognitoAuth.cacheTokensScopes (https://localhost:1234/src.74b10521.js:58709:65)
    at CognitoAuth.getTokenQueryParameter (https://localhost:1234/src.74b10521.js:58647:10)
    at CognitoAuth.parseCognitoWebResponse (https://localhost:1234/src.74b10521.js:58585:12
rdpacheco commented 5 years ago

@brachi-wernick I didn't "fix" mine so much as get around it. My issue was that I was using a VueJS router that was using Hash history mode. So all of my URLs looked like this: https://domain.com/#/user/userId.

VueJS automatically reformatted my hash urls to look that way. So if i typed the following: https://domain.com/#some-route

Vue would change it to: https://domain.com/#/some-route

Now, when using the amazon-cognito-auth-js lib, access tokens come back as a hash param. So my Vue app was trying to rewrite them from: https://domain.com/#access-token=...

to: https://domain.com/#/access-token=...

And then when the amazon-cognito-auth-js lib tried to auto detect the token, it would error out with that atob message.

To get around it, i moved to History mode URLs, so i would write urls like this: https://domain.com/user/userId

This way, Vue does not auto hijack my hash params and the cognito lib can do it's thing.

brachi-wernick commented 5 years ago

thanks @rdpacheco. after digging in the code, I found another ugly workaround : if I add questionmark with dummy search param in the end of the URL this work fine. because it doesn't try to parse the URL part with te poundsign.

for example: this https://domain.com/#/some-route turned out to be https://domain.com/#/some-route?aws