abacritt / angularx-social-login

Social login and authentication module for Angular 17
636 stars 387 forks source link

Error on successful login (google) #558

Closed yura-brd closed 1 year ago

yura-brd commented 2 years ago

Upon successful authorization, an error occurs when decoding the token Error in function decodeJwt:
Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded. ![2022-08-01_22-54-09](https://user-images.githubusercontent.com/13005888/182234615-dcee3441-340b-40c0-a0a7-51e0636af8e6.png) *same error on demo site(https://abacritt.github.io/angularx-social-login/)

*the problem, most likely, is the presence of Cyrillic in the data. (btoa)

kattoshi commented 2 years ago

Refer to the site here https://gist.github.com/subhamchbty/0ea970b559bc8d15e6f42bf2d1258eae

Changing "projects/lib/src/providers/google-login-provider.ts" worked

  private decodeJwt(idToken: string): Record<string, string | undefined> {
    var base64Url = idToken.split(".")[1];
    var base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
    var jsonPayload = decodeURIComponent(
      window.atob(base64)
        .split("")
        .map(function (c) {
          return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
        })
        .join("")
    );

    return JSON.parse(jsonPayload);
  }
kattoshi commented 2 years ago

I fixed #578 . Please wait for the next release.

Heatmanofurioso commented 2 years ago

@yura-brd @kattoshi Released V1.2.3

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.