Git Product home page Git Product logo

wavezync / vue3-google-signin Goto Github PK

View Code? Open in Web Editor NEW
142.0 6.0 16.0 1.18 MB

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

Home Page: https://vue3-google-signin.wavezync.com/

License: MIT License

JavaScript 1.02% HTML 0.53% Vue 21.29% TypeScript 77.15%
composition-api google-authentication google-identity-services google-oauth2 google-sign-in vue vue3 vue3-typescript vuejs typescript

vue3-google-signin's People

Contributors

codedealer avatar kasvith avatar oliver-youdooh avatar philippedasilva-orizone avatar raevilman avatar rukshanjs avatar zuhno avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

vue3-google-signin's Issues

How to change expiration time to be more than 60 min?

Extend Expiration Time Beyond 60 Minutes

Requesting the ability to set expiration times greater than 60 minutes. This enhancement would provide more flexibility for users who require longer expiration periods. Open to discussion and collaboration on implementation.

Add a FAQ

We need a FAQ section on the docs.

I see a lot of people coming to discussions thread to understand how to use custom scopes etc.
It would be wise to provide some examples and add relevant docs as a FAQ

Cannot login in webview (tauri)

I'm trying vue3-google-signin in vue3 using tauri as a backend, but this does not work. The browser windows for authentication is opened in the embedded browser and that is disallowed by google policies, so I get an error message as in the attached screenshot.

image

Remove 'cb triggered' console log

Hi there,

Any chance of removing this debugging statement? Currently this is outputting in our production env.

console.log("cb triggered");

I find it would be useful only in a development environment. Perhaps we can make this a development environment output instead?

if (process.env.NODE_ENV === "development") {
    console.log("cb triggered"); 
}

Happy to open a pull request if you like.

Plans for Dynamic clientId Updates?

Hello :)

Is your feature request related to a problem? Please describe.
I'm currently facing a limitation with the static assignment of the clientId value. My backend server provides redirect_uri and clientId, which I wish to dynamically utilize in my application. However, the current implementation does not allow for changing the clientId symbol value after initialization, leading to inflexibility in adapting to different server responses.

Describe the solution you'd like
I would like the ability to dynamically update the clientId value. Specifically, the solution would involve:

  1. Using setClientId to change the clientId symbol value.
  2. Modifying useOneTap, useTokenClient, useCodeClient hooks to accept clientId as part of the options object, enabling the use of either the initialization value or the dynamically provided clientId.

To implement the above, it would be necessary to optionally accept clientId during app installation.

Describe alternatives you've considered
An alternative could be a more static configuration, but this lacks the flexibility required for different backend responses. I'm open to other suggestions that could provide similar functionality.

Additional context
The inability to dynamically update the clientId hinders the adaptability of the application to different backend environments. Also, there was an issue with the package.json version not being updated, causing a failure in GitHub Action and preventing the NPM version from updating. This is an additional context that might be relevant to the overall functionality and deployment process.

Google Signin button not showing with Quasar + Vite

The google sign-in button is not showing on a page setup with Quasar and Vite.
I got the following warnings when including the component in a page:

runtime-core.esm-bundler.js:38 [Vue warn]: inject() can only be used inside setup() or functional components.
warn2 @ runtime-core.esm-bundler.js:38
inject @ runtime-core.esm-bundler.js:1637
setup @ index.es.js:75
callWithErrorHandling @ runtime-core.esm-bundler.js:155
setupStatefulComponent @ runtime-core.esm-bundler.js:7187
setupComponent @ runtime-core.esm-bundler.js:7142
mountComponent @ runtime-core.esm-bundler.js:5491
processComponent @ runtime-core.esm-bundler.js:5466
patch @ runtime-core.esm-bundler.js:5068
mountChildren @ runtime-core.esm-bundler.js:5252
processFragment @ runtime-core.esm-bundler.js:5425
patch @ runtime-core.esm-bundler.js:5061
componentUpdateFn @ runtime-core.esm-bundler.js:5605
run @ reactivity.esm-bundler.js:185
instance.update @ runtime-core.esm-bundler.js:5712
setupRenderEffect @ runtime-core.esm-bundler.js:5726
mountComponent @ runtime-core.esm-bundler.js:5508
processComponent @ runtime-core.esm-bundler.js:5466
patch @ runtime-core.esm-bundler.js:5068
mountChildren @ runtime-core.esm-bundler.js:5252
mountElement @ runtime-core.esm-bundler.js:5162
processElement @ runtime-core.esm-bundler.js:5145
patch @ runtime-core.esm-bundler.js:5065
componentUpdateFn @ runtime-core.esm-bundler.js:5605
run @ reactivity.esm-bundler.js:185
instance.update @ runtime-core.esm-bundler.js:5712
setupRenderEffect @ runtime-core.esm-bundler.js:5726
mountComponent @ runtime-core.esm-bundler.js:5508
processComponent @ runtime-core.esm-bundler.js:5466
patch @ runtime-core.esm-bundler.js:5068
render2 @ runtime-core.esm-bundler.js:6227
mount @ runtime-core.esm-bundler.js:4427
app.mount @ runtime-dom.esm-bundler.js:1590
start @ client-entry.js?t=1664629411311:71
Promise.then (async)
(anonymous) @ client-entry.js?t=1664629411311:82
Show 4 more frames
runtime-core.esm-bundler.js:38 [Vue warn]: onMounted is called when there is no active component instance to be associated with. Lifecycle injection APIs can only be used during execution of setup(). If you are using async setup(), make sure to register lifecycle hooks before the first await statement.
warn2 @ runtime-core.esm-bundler.js:38
injectHook @ runtime-core.esm-bundler.js:2699
(anonymous) @ runtime-core.esm-bundler.js:2710
useGsiScript @ index.es.js:37
setup @ index.es.js:77
callWithErrorHandling @ runtime-core.esm-bundler.js:155
setupStatefulComponent @ runtime-core.esm-bundler.js:7187
setupComponent @ runtime-core.esm-bundler.js:7142
mountComponent @ runtime-core.esm-bundler.js:5491
processComponent @ runtime-core.esm-bundler.js:5466
patch @ runtime-core.esm-bundler.js:5068
mountChildren @ runtime-core.esm-bundler.js:5252
processFragment @ runtime-core.esm-bundler.js:5425
patch @ runtime-core.esm-bundler.js:5061
componentUpdateFn @ runtime-core.esm-bundler.js:5605
run @ reactivity.esm-bundler.js:185
instance.update @ runtime-core.esm-bundler.js:5712
setupRenderEffect @ runtime-core.esm-bundler.js:5726
mountComponent @ runtime-core.esm-bundler.js:5508
processComponent @ runtime-core.esm-bundler.js:5466
patch @ runtime-core.esm-bundler.js:5068
mountChildren @ runtime-core.esm-bundler.js:5252
mountElement @ runtime-core.esm-bundler.js:5162
processElement @ runtime-core.esm-bundler.js:5145
patch @ runtime-core.esm-bundler.js:5065
componentUpdateFn @ runtime-core.esm-bundler.js:5605
run @ reactivity.esm-bundler.js:185
instance.update @ runtime-core.esm-bundler.js:5712
setupRenderEffect @ runtime-core.esm-bundler.js:5726
mountComponent @ runtime-core.esm-bundler.js:5508
processComponent @ runtime-core.esm-bundler.js:5466
patch @ runtime-core.esm-bundler.js:5068
render2 @ runtime-core.esm-bundler.js:6227
mount @ runtime-core.esm-bundler.js:4427
app.mount @ runtime-dom.esm-bundler.js:1590
start @ client-entry.js?t=1664629411311:71
Promise.then (async)
(anonymous) @ client-entry.js?t=1664629411311:82
Show 6 more frames
runtime-core.esm-bundler.js:38 [Vue warn]: onUnmounted is called when there is no active component instance to be associated with. Lifecycle injection APIs can only be used during execution of setup(). If you are using async setup(), make sure to register lifecycle hooks before the first await statement.
warn2 @ runtime-core.esm-bundler.js:38
injectHook @ runtime-core.esm-bundler.js:2699
(anonymous) @ runtime-core.esm-bundler.js:2710
useGsiScript @ index.es.js:40
setup @ index.es.js:77
callWithErrorHandling @ runtime-core.esm-bundler.js:155
setupStatefulComponent @ runtime-core.esm-bundler.js:7187
setupComponent @ runtime-core.esm-bundler.js:7142
mountComponent @ runtime-core.esm-bundler.js:5491
processComponent @ runtime-core.esm-bundler.js:5466
patch @ runtime-core.esm-bundler.js:5068
mountChildren @ runtime-core.esm-bundler.js:5252
processFragment @ runtime-core.esm-bundler.js:5425
patch @ runtime-core.esm-bundler.js:5061
componentUpdateFn @ runtime-core.esm-bundler.js:5605
run @ reactivity.esm-bundler.js:185
instance.update @ runtime-core.esm-bundler.js:5712
setupRenderEffect @ runtime-core.esm-bundler.js:5726
mountComponent @ runtime-core.esm-bundler.js:5508
processComponent @ runtime-core.esm-bundler.js:5466
patch @ runtime-core.esm-bundler.js:5068
mountChildren @ runtime-core.esm-bundler.js:5252
mountElement @ runtime-core.esm-bundler.js:5162
processElement @ runtime-core.esm-bundler.js:5145
patch @ runtime-core.esm-bundler.js:5065
componentUpdateFn @ runtime-core.esm-bundler.js:5605
run @ reactivity.esm-bundler.js:185
instance.update @ runtime-core.esm-bundler.js:5712
setupRenderEffect @ runtime-core.esm-bundler.js:5726
mountComponent @ runtime-core.esm-bundler.js:5508
processComponent @ runtime-core.esm-bundler.js:5466
patch @ runtime-core.esm-bundler.js:5068
render2 @ runtime-core.esm-bundler.js:6227
mount @ runtime-core.esm-bundler.js:4427
app.mount @ runtime-dom.esm-bundler.js:1590
start @ client-entry.js?t=1664629411311:71
Promise.then (async)
(anonymous) @ client-entry.js?t=1664629411311:82
Show 6 more frames
runtime-core.esm-bundler.js:38 [Vue warn]: onUnmounted is called when there is no active component instance to be associated with. Lifecycle injection APIs can only be used during execution of setup(). If you are using async setup(), make sure to register lifecycle hooks before the first await statement.
warn2 @ runtime-core.esm-bundler.js:38
injectHook @ runtime-core.esm-bundler.js:2699
(anonymous) @ runtime-core.esm-bundler.js:2710
setup @ index.es.js:123
callWithErrorHandling @ runtime-core.esm-bundler.js:155
setupStatefulComponent @ runtime-core.esm-bundler.js:7187
setupComponent @ runtime-core.esm-bundler.js:7142
mountComponent @ runtime-core.esm-bundler.js:5491
processComponent @ runtime-core.esm-bundler.js:5466
patch @ runtime-core.esm-bundler.js:5068
mountChildren @ runtime-core.esm-bundler.js:5252
processFragment @ runtime-core.esm-bundler.js:5425
patch @ runtime-core.esm-bundler.js:5061
componentUpdateFn @ runtime-core.esm-bundler.js:5605
run @ reactivity.esm-bundler.js:185
instance.update @ runtime-core.esm-bundler.js:5712
setupRenderEffect @ runtime-core.esm-bundler.js:5726
mountComponent @ runtime-core.esm-bundler.js:5508
processComponent @ runtime-core.esm-bundler.js:5466
patch @ runtime-core.esm-bundler.js:5068
mountChildren @ runtime-core.esm-bundler.js:5252
mountElement @ runtime-core.esm-bundler.js:5162
processElement @ runtime-core.esm-bundler.js:5145
patch @ runtime-core.esm-bundler.js:5065
componentUpdateFn @ runtime-core.esm-bundler.js:5605
run @ reactivity.esm-bundler.js:185
instance.update @ runtime-core.esm-bundler.js:5712
setupRenderEffect @ runtime-core.esm-bundler.js:5726
mountComponent @ runtime-core.esm-bundler.js:5508
processComponent @ runtime-core.esm-bundler.js:5466
patch @ runtime-core.esm-bundler.js:5068
render2 @ runtime-core.esm-bundler.js:6227
mount @ runtime-core.esm-bundler.js:4427
app.mount @ runtime-dom.esm-bundler.js:1590
start @ client-entry.js?t=1664629411311:71
Promise.then (async)
(anonymous) @ client-entry.js?t=1664629411311:82
Show 5 more frames
runtime-core.esm-bundler.js:38 [Vue warn]: Missing ref owner context. ref cannot be used on hoisted vnodes. A vnode with ref must be created inside the render function. 
  at <GoogleSignInButton onSuccess=fn<handleLoginSuccess> onError=fn<handleLoginError> > 
  at <MainLayout> 
  at <App>

I have correctly done all the other steps (the setup of the plugin passing clientId + scopes)

Google Loading GSI Error

Describe the bug

Whenever loading the library it results into this given error:

GET https://accounts.google.com/gsi/client net::ERR_INVALID_HANDLE

var initialize = () => {
isLoading.value = true;
scriptTag = createScriptTag();
document.head.appendChild(scriptTag); ==> Specifically fails here
scriptTag.onload = () => {
isLoading.value = false;
loaded.value = true;
};
scriptTag.onerror = () => {
isLoading.value = false;
error.value = true;
};
};

To Reproduce

On both nuxt-vue3-google-signin and vue3-google-signin it fails.

On firefox Nuxt 3 gets stuck because of the error.

On Google Chrome it's completely blocked.

Need token's iat and exp as part of DecodedGoogleUser

Is your feature request related to a problem? Please describe.
Can we have JWT token's iat and exp fields as part of DecodedGoogleUser?

Describe the solution you'd like
If you are fine with having these two fields as part of the DecodedGoogleUser, I can send a PR for same.
Something like below:

export interface DecodedGoogleUser {
  email: string;
  email_verified: boolean;
  hd: string;
  family_name: string;
  given_name: string;
  name: string;
  id: string;
  picture: string;
  issued_at: number;
  expires_at: number;
}

Usage with Google API's and firebase

Hello,
Is there an example of using, say, calendar api with this lib ? And also, something that would use Firebase Google Auth together with this one ? How should they behave or interact ?
Thank you

MS Authentication

Thanks for your support to create for the possibility of authentication with google.

Could you imagine using another repo or this to extend Microsoft Login?

The background of my question is that many business applications, i.e. applications within companies in Europe rely on Microsoft products (Office365). Here it would be great if there was a simple way of authentication, similar to this repository.
This would also provide access to the development of "MS Teams" apps.
Is this already in planning?

Invalid access access token format

Describe the bug
Success callback returns incorrect JWT formated access token, somethink like ya29.a0A . Valid JWT token consists from header,payload and signature xxxxx.yyyyy.zzzzz

To Reproduce
Steps to reproduce the behaviour:

  1. Go to page with google oauth
  2. Click on button to sign
  3. See at console response with access_token

Incorrect 'module' Field and Missing 'types' Field in 'exports' Causing TypeScript Errors in ES Environment

Describe the bug
When trying to import the 'vue3-google-signin' library in an ES environment, I encountered a type error indicating the absence of a declaration file for the module. The detailed error message is as follows:

Could not find a declaration file for module 'vue3-google-signin'. '/Users/junolee/Documents/mine/google-news-rss-pusher/node_modules/.pnpm/[email protected][email protected]/node_modules/vue3-google-signin/dist/index.es.js' implicitly has an 'any' type.
  There are types at '/Users/junolee/Documents/mine/google-news-rss-pusher/apps/@front/client/node_modules/vue3-google-signin/dist/plugin.d.ts', but this result could not be resolved when respecting package.json "exports". The 'vue3-google-signin' library may need to update its package.json or typings. ts(7016)

To Reproduce
Steps to reproduce the behavior:

  1. Set up a project with the 'vue3-google-signin' package.
  2. Attempt to import the package in an ES module environment.
  3. Observe the TypeScript error related to type declarations.

Reproducible Example
Currently, I do not have a reproducible example on platforms like StackBlitz or CodeSandbox. I will update this section if I am able to create one.

Expected behaviour
The expected behavior is for the module to be imported without any type errors, with TypeScript being able to find and use the declaration files correctly.

Additional context
To resolve this issue, the types field should be added under "exports" > "." in the package.json. Additionally, the module field is incorrectly pointing to a CJS module. It should instead specify the entry point for an ES module, typically using a .mjs or .js extension.

Contribution Proposal
I am considering contributing to the 'vue3-google-signin' library to address this issue. I would like to propose corrections to the package.json file, particularly adding the types field under "exports" > ".", and correcting the module field to accurately point to an ES module entry point. I wanted to inquire if contributing these changes would be appropriate.

Expose a method to get OAuth2 redirect URL from code client

To work with platforms like Electron/Tauri it's necessary to have a method to do a redirect login flow on system browsers to comply with security policies from google.

As @vincenzoml mentioned he has a requirement to use this library with Tauri, but the browser version of tauri webview prevents google login.

We need a method to obtain the redirect URL so these platforms can do a system call to open the default browser.

Related issue #14

How do I log out

I have tested the button in Nuxt3 and it works well to log in, but what do I do if I want to log out?

Thanks, and sorry if the question is very basic.

Laravel socialite

Hi!

I use laravel (socialite) as backend
I tried all the combinations suggested, but I always have the same error.

Client error: GET https://www.googleapis.com/oauth2/v3/userinfo?prettyPrint=false resulted in a 401 Unauthorized response:\n{\n \"error\": \"invalid_request\",\n \"error_description\": \"Invalid Credentials\"\n}\n

I used the same google client id for the backend and the front

Front (Nuxt)

const handleLoginSuccess = async (response: CredentialResponse) => {
  const { credential } = response
  await useFetch('/auth/social/google', {
    method: 'post',
    body: { token:  credential,  provider: 'google' }
  }).then((response) => {
    console.log(response.data.value)
  }).catch((error) => {
    console.log(error)
  }).finally(() => {
    loading.value = false
  })
}

Laravel socialite
Socialite::driver($request->input('provider'))->stateless()->userFromToken($request->input('token'));

Merci!!!

FedCM becomes mandatory

Describe the bug
GSI_LOGGER]: Your client application uses one of the Google One Tap prompt UI status methods that may stop functioning when FedCM becomes mandatory. Refer to the migration guide to update your code accordingly and opt-in to FedCM to test your changes. Learn more: https://developers.google.com/identity/gsi/web/guides/fedcm-migration?s=dc#display_moment and https://developers.google.com/identity/gsi/web/guides/fedcm-migration?s=dc#skipped_moment

To Reproduce
Steps to reproduce the behaviour:

  1. Go to https://vue3-google-signin.wavezync.com/guide/one-tap-login.html
  2. Sign in with one tap
    image
  3. In console there is this error:
    [GSI_LOGGER]: Your client application uses one of the Google One Tap prompt UI status methods that may stop functioning when FedCM becomes mandatory. Refer to the migration guide to update your code accordingly and opt-in to FedCM to test your changes. Learn more: https://developers.google.com/identity/gsi/web/guides/fedcm-migration?s=dc#display_moment and https://developers.google.com/identity/gsi/web/guides/fedcm-migration?s=dc#skipped_moment

Reproducible Example
If you can please provide a reproducible example with Stackbliz, CodeSandbox or any other suitable service

Expected behaviour
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Vite build fails when building vue3-google-signin package in my app

Describe the bug
My build fails when trying to import from vue package in the dist/index.es.js on line 1

To Reproduce
I admit I didn't try to reproduce it on another project but on mine it would consist on

  1. clone @antfu/vitesse template repository
  2. install vue3-google-signin package latest version (should do the same with previous too)
  3. implement GoogleSignIn button in an existing page
  4. build the project
  5. Note the build error in the console output

Expected behaviour
Should build :)

Screenshots
Screenshot 2022-11-02 at 00 24 45

Additional context
I override my local install in node_modules/vue3-google-signinsimply adding the "type": "module" line in package.jsonand the build succeed.

Missing TypeScript Type Definitions in 1.3.4 Distribution

Describe the bug

Hello,

I've noticed that the TypeScript type definitions, previously available in the dist folder, are missing in version 1.3.4 of vue3-google-signin. This change has led to TypeScript compilation errors in my project due to the missing type information.

As a temporary workaround, I have manually added the type definitions to my project like below, but it would be ideal to have them included in the package itself.
import GoogleSignInButton from 'vue3-google-signin/dist/components/GoogleSignInButton.vue';

To Reproduce
Steps to reproduce the behaviour:

  1. Import GoogleSigninButton to your project as described in README.
    import { CredentialResponse, GoogleSignInButton } from 'vue3-google-signin';
  2. See the type error.

Expected behaviour

  1. The import should return no type errors with the import like below.
    import { CredentialResponse, GoogleSignInButton } from 'vue3-google-signin';

Additional context
It occurs in the development environment.

Merge type declarations with global object

Currently, we don't add any types to the global namespace, But since we use the google library we have all the methods available in the global object. Its nice to have this when you install the library

ClientId may be undefined when using FedCM login

Describe the bug
When using FedCM sign-in in Google Chrome, the clientId field passed to the callback may be undefined.

To Reproduce
Steps to reproduce the behaviour:

  1. Log in to Google Chrome
  2. Open a page that calls useOneTap() method to display Google’s OneTap sign in UI.
  3. When clicking Continue as [[your name]], onSuccess() is not called, and onError() is called without arguments.

Reproducible Example
If you can please provide a reproducible example with Stackbliz, CodeSandbox or any other suitable service

Expected behaviour
A clear and concise description of what you expected to happen.

Screenshots

image

Desktop (please complete the following information):

  • OS: [e.g. iOS] Windows 11
  • Browser [e.g. chrome, safari] Chrome
  • Version [e.g. 22] 125.0.6422.142

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

DOMException: CredentialContainer request not supported

Hi!
After many hours on this and lot of searchs, i come here...

Describe the bug
On a fresh new Nuxt project I'm trying to add Google OneTap SignIn with nuxt-vue3-google-signin.
I added the exact same code as provided in the doc but I have this console error after clicking login button.
The errors seems coming from vue3-google-signin.

image

Screenshots
image

image

Desktop (please complete the following information):
Firefox 122.0
Node v20.11.0
NPM 10.4.0
Nuxt 3.10.0
Vue 3.4.15
nuxt-vue3-google-signin 0.0.10

Memory Leak On Nuxt 3

Memory Leak on server using onetap composable on app.vue

I face Memory Leak issue on my nuxt 3 application in production when I use OneTap Composable in my app.vue file to have the ability to login my users in whole application
is there any solution to fix this issue or something in the package should be fixed?
i also use SSR in my app and run the onetap login() in onMounted to make sure it is hydrated on client-side and also the isReady variable is not working on production environment
it would be great to help me guys
thanks

here's my code

onMounted(() => { setTimeout(() => { if (!isAuthenticated.value) { console.log("One tap"); login(); } }, 200); });

const { login, isReady } = useOneTap({ onError: handleOneTapError, disableAutomaticPrompt: true, onSuccess: handleOneTapSuccess, });

Integrate JWT token for credential response

Discussed in #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):

      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?

Getting "This document requires 'TrustedScript' assignment" after login

Hello,
I am not able to login, I get this error after obtaining a credential. I am using the most basic example:


<template>
  <GoogleSignInButton
    @success="handleLoginSuccess"
    @error="handleLoginError"
  ></GoogleSignInButton>
</template>

</template>

<script setup>

import {GoogleSignInButton} from "vue3-google-signin";
const handleLoginSuccess = (response) => {
  console.log('response:')
  const { credential } = response;
  console.log("Access Token", credential)
}

const handleLoginError = (response) => {
  console.log("Error logging in")
}
</script>

<style>

</style>

vue-gapi relationship

πŸ‘‹πŸ» @kasvith!

I have helped maintain vue-gapi over the years, and your plugin was brought to my attention as we do not currently support Google Identity Services.

My availability is becoming limited, so I would certainly be open to working with you to bridge these projects via any number of options, including:

  • deprecating vue-gapi and pointing people here
  • moving these projects under a generalized GitHub organization
  • extracting some core framework-agnostic library (that could be used across Vue, React, etc)

Let me know if you have any thoughts / preference!

Also looping in @fmeyertoens and @cedpoilly who have helped with vue-gapi as well πŸ˜„

Make more event cases

When the button is clicked and the login() function is executed, we have no way to control the pop-up window closing situation. If you close it, there is no feedback for that case. Using AuthCodeFlowErrorResponse, this case cannot be managed.

It would be great to add more events for cases such as the window closing, an error occurring during the window launch, etc.

This event, for my needs, would be useful to manage the states of my custom button: if the button is clicked and the pop-up window has opened, I want to prevent the button from being pressed. In case the user closes the window, the event tells me so and then I can manage the button to re-enable it.

Tell me if you think it's a good idea to create more events like this.

Thanks for read me!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.