From a2efbab0e432d1dc2b3086b2743a67d4dda29940 Mon Sep 17 00:00:00 2001 From: kattoshi Date: Sat, 13 Aug 2022 14:00:38 +0900 Subject: [PATCH] fixes "atob" decode failed to execute --- projects/lib/src/providers/google-login-provider.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/projects/lib/src/providers/google-login-provider.ts b/projects/lib/src/providers/google-login-provider.ts index d5a65d12..ff0fa457 100644 --- a/projects/lib/src/providers/google-login-provider.ts +++ b/projects/lib/src/providers/google-login-provider.ts @@ -186,6 +186,16 @@ export class GoogleLoginProvider extends BaseLoginProvider { } private decodeJwt(idToken: string): Record { - return JSON.parse(window.atob(idToken.split('.')[1])); + const base64Url = idToken.split(".")[1]; + const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/"); + const jsonPayload = decodeURIComponent( + window.atob(base64) + .split("") + .map(function (c) { + return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2); + }) + .join("") + ); + return JSON.parse(jsonPayload); } }