wavezync / vue3-google-signin

Google OAuth2 plugin for Vue3 Apps. This uses latest Google Identity Service Library. It also provides set of composables which can be used easily to implement different authentication strategies
https://vue3-google-signin.wavezync.com/
MIT License
161 stars 17 forks source link

Integrate JWT token for credential response #28

Closed kasvith closed 2 years ago

kasvith commented 2 years ago

Discussed in https://github.com/syetalabs/vue3-google-signin/discussions/27

by @philippedasilva-orizone

Originally posted by **philippedasilva-orizone** October 23, 2022 Hey, I thought we could all benefit from getting a decrypted jwt token in the CredentialResponse type instead of the actual string returned by Google on successfully logging the user. I know it would probably add a dependency but I believe we, end users of the component, would anyway still have to add it. My own implementation uses the universal-base64Url package (https://www.npmjs.com/package/universal-base64url): ```typescript const base64Url = jwt.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('') ); const decodedToken = JSON.parse(jsonPayload); console.log(decodedToken); ``` Ideally, I would actually get the CredentialResponse with a typed "credential" so I can directly benefit from my IDE intellisense with a `decodedToken.email` or `decodedToken.family_name`... Any reason not to do it?
kasvith commented 2 years ago

Closed by #29