Code Monkey home page Code Monkey logo

vue-google-oauth2's Introduction

DEPRECATED - no longer actively maintained

This plugin does not support the new Google authentication system(GIS). You need to migrate by referring to this document.

vue-google-oauth2

Handling Google sign-in and sign-out for Vue.js applications.

npm bundle size GitHub vue-google-oauth2

We support TypeScript and Nuxt. ๐Ÿ˜Ž For Vue3 applications, please refer to here

Front-end Demo

Installation

Installation with npm

npm install vue-google-oauth2

Installation with yarn

yarn add vue-google-oauth2

Initialization

//src/main.js
import GAuth from 'vue-google-oauth2'
const gauthOption = {
  clientId: 'CLIENT_ID.apps.googleusercontent.com',
  scope: 'profile email',
  prompt: 'select_account'
}
Vue.use(GAuth, gauthOption)

Please Don't use plus.login scope. It will be deprecated.

Initialization for Nuxt

  1. creates plug-in file for nuxt

    // plugins/vue-google-oauth2.js
    // file name can be changed to whatever you want
    import Vue from 'vue'
    import GAuth from 'vue-google-oauth2'
    
    const gauthOption = {
      clientId: 'CLIENT_ID.apps.googleusercontent.com',
      scope: 'profile email',
      prompt: 'select_account'
    }
    Vue.use(GAuth, gauthOption)
  2. adds plugin to nuxt config file

    ...
    plugins: [
      ...
      './plugins/vue-google-oauth2'
    ],
    
    ...

Options

Property Type Required Description
clientId String Required. The app's client ID, found and created in the Google Developers Console.
scope String Optional. Default value is profile email. Full list of scopes.
prompt String Optional. This value using for authCode. The possible values are select_account or consent. Default value is select_account. To get refresh token from auth code, use consent.
fetch_basic_profile Boolean Optional. If set to true, email profile openid will be automatically added as scope. Default value is true.

Methods

Property Description Type
GoogleAuth return of gapi.auth2.getAuthInstance() Object
isAuthorized Whether or not you have auth Boolean
isInit Whether or not api init Boolean
isLoaded Whether or not api init. will be deprecated. Function
signIn function for sign-in Function
getAuthCode function for getting authCode Function
signOut function for sign-out Function

Usages

Getting authorization code

The authCode that is being returned is the one-time code that you can send to your backend server, so that the server can exchange for its own access_token and refresh_token.

The access_token and refresh_token can be saved in backend storage for reuse and refresh. In this way, you can avoid exposing your api key or secret key whenever you need to use various google APIs.

const authCode = await this.$gAuth.getAuthCode()
const response = await this.$http.post('http://your-backend-server-api-to-use-authcode', { code: authCode, redirect_uri: 'postmessage' })

Sign-in: Directly get back the access_token and id_token

const googleUser = await this.$gAuth.signIn()
// googleUser.getId() : Get the user's unique ID string.
// googleUser.getBasicProfile() : Get the user's basic profile information.
// googleUser.getAuthResponse() : Get the response object from the user's auth session. access_token and so on
this.isSignIn = this.$gAuth.isAuthorized

refer to google signIn reference : GoogleUser

Sign-out

Handling Google sign-out

const response = await this.$gAuth.signOut()

Extra - Directly get access_token and refresh_token on Server-side

To get access_token and refresh_token in server side, the data for redirect_uri should be postmessage. postmessage is magic value for redirect_uri to get credentials without actual redirect uri.

Curl

curl -d "client_id=YOUR_CLIENT_ID&\
  client_secret=YOUR_CLIENT_SECRET&\
  redirect_uri=postmessage&\
  grant_type=authorization_code&\
  code=YOUR_AUTH_CODE" https://accounts.google.com/o/oauth2/token

Sample Code

Additional Help

FAQ

The failure of initialization happens

You can check the brower console to check errors which occur during initialization. The most of errors are from inproper setting of google oauth2 credentials setting in Google Developer Console. After changing the settings, you have to do hard refresh to clear your caches.

Type Errors

Follow the documentation provided here to add $gAuth as a property for preventing lint errors.

vue-google-oauth2's People

Contributors

byeongukchoi avatar dzakki avatar fidemin avatar fpierre avatar guruahn avatar h-matsuo avatar jtandiyo avatar katiedotson avatar printscreen avatar romainr avatar sgtchrome avatar supenguin avatar thomasleveil avatar yokoel 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  avatar

vue-google-oauth2's Issues

question: why not use state?

OAuth guidelines recommend using state parameter for preventing CSRF attacks, but in your examples for server-side code handling state isn't involved. It's practically the same when backend initiates sing in, a user authenticates on Google and Google redirects back to the backend with code and when frontend initiates sign in, the user authenticates with google and fronted receives code that is being sent to the backend. So in both cases backend needs state to verify, and sing in must be initiated involving the backend?

Types declaration is missing

I have a typescript VueJS project. When adding this component, I'm getting Could not find a declaration file for module 'vue-google-oauth2' error.
I've added the typedefs from this repo but that had no effect.

how to get token.pickle by authorization_response or auth_code

flow.fetch_token(authorization_response=authorization_response)
credentials = flow.credentials

I am using Django in backend and VUE in frontend, wanted to use this way.

I have also tried to get the token.pickle with auth_code
flow.fetch_token(code=auth_code)
This also didn't work.

I want to use token.pickle for multiple time like this. is there any way to get that?

Getting additional info while getAuthCode processing

I'm using (a) Handling Google sign-in, getting the one-time authorization code from Google for getting code and then send it to backend. It works great but there is one feature/info more which I need when user make authentication. I need mail address which user choose and authenticated. So is it possible to know address while getting authorizationCode ? I hope it is possible because I don't want to use second approach: (b) Alternatively, if you would like to directly get back the access_token and id_token only for getting address. Thanks!

Invalid JSON payload received. Unexpected token.\nclient_id=xxxx\n^ error when use authCode to exchange access and refresh token

Describe the bug
I'm used vue-google-oauth2 to get authCode from google, then I want to use it to exchange access and refresh token by below:

curl -d "client_id=0123456789012-xxxxxxxxxxx&\
  client_secret=CLIENT_SECRET&\
  redirect_uri=postmessage&\
  grant_type=authorization_code&\
  code=AUTH_CODE" -H "Content-Type: application/json" -H "Content-Type: application/x-www-form-urlencoded" --header 'Accept: application/json' https://accounts.google.com/o/oauth2/token

but I get an 400 error:

{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unexpected token.\nclient_id=012345678\n^",
    "status": "INVALID_ARGUMENT"
  }
}

What I went wrong? Thanks for your support

To Reproduce

Replace client_id, client_secret, auth_code and run above Curl command

Expected behavior

Google OAuth response access token and refresh token

Get refresh_token everytime from backend

Hello,

I have implement the backend (.netCore 3) part to request access_token and refresh_token by authCode, but apparently I get refresh_token only the first time a user make the login with my App. Looking at google oauthplayground I see that they add another parameter on client request "access_type=offline", after some reading I realized that this is the way to get refresh_token everytime.

Is there any workaround to pass this param as an option ?

Appreciated

refresh token exchange

Hi,

Is there any way to get authcode which can be exchanged with refresh token everytime I get an authcode.
I get refresh token only the first time.

Thanks

Tip for handling the auth code in python backend

Hi, the library works perfectly and gets the auth code on the frontend.
Now I made a POST route in flask(python web framework) which uses the exact code from the Python backend sample provided in this repo.
For some reason, I get this error - invalid_grantMalformed auth code.
I've been scratching my head over this for a while now.
Can somebody please shed some light on what could be the potential reasons for this error.

Although of set fetch_basic_profile to false, email profile openid are automatically added as scope.

Describe the bug
I'm using this library to get authCode from Google OAuth server, I set scope to adwords and fetch_basic_profile to false but when i see response from server, email profile openid are automatically added as scope.
My gAuthOptions:

gauthOption = {
    clientId: process.env.VUE_APP_GOOGLE_CLIENT_ID,
    fetch_basic_profile: false,
    prompt: "consent",
    access_type: "offline",
    scope: "https://www.googleapis.com/auth/adwords"
  };

Expected behavior
Server only response for adwords scope without email profile openid

TSlint error

Not really a bug but I am getting the following ESlint warning:

WARNING in /Users/simon/dev/omada/bo/node_modules/vue-google-oauth2/index.ts(138,10):
138:10 Parentheses are required when invoking a constructor
    136 |   };
    137 | 
  > 138 |   return new (Auth as any);
        |          ^
    139 | })();
    140 | 

I have tried different combinations of parenthesis but couldn't propose a fix. Could you please have a quick look into it?

Version: typescript 3.5.3, tslint 5.20.0

Question about getAuthCode and access_token. (or maybe feature request?)

Hi. Thank you for sharing good code.
This has helped me to improve my productivity.

During the development, I have questions about access_token.
Is there any way to get access_token from the client side even if I log in with getAuthCode()?
README.md says that I can only access google user object through signIn() function. However, even if I authenticate on the server side with getAuthCode(), client can access to google user object by window.gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse() (GoogleUser.getAuthResponse)
So, I would like to ask you how to access access_token or user profile in login via getAuthCode().

If you have to access windows.gapi.auth2.getAuthInstance (as described above), it would be nice if you have an API that you can access directly from vue-google-auth2.

I'm sure you're busy, but I'd appreciate it if you could help me.


์•ˆ๋…•ํ•˜์„ธ์š”.
๋จผ์ € ์ข‹์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๊ณต์œ ํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๋•๋ถ„์— ์ƒ์‚ฐ์„ฑ ํ–ฅ์ƒ์— ๋งŽ์€ ๋„์›€์ด ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

์›น์•ฑ์„ ๊ฐœ๋ฐœํ•˜๋˜ ์ค‘ access_token ๊ด€๋ จํ•œ ๊ถ๊ธˆ์ฆ์ด ์ƒ๊ฒจ์„œ ์งˆ๋ฌธ์„ ๋‚จ๊น๋‹ˆ๋‹ค.
ํ˜น์‹œ getAuthCode ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ์„œ๋ฒ„ ์‚ฌ์ด๋“œ์—์„œ ๋กœ๊ทธ์ธ ํ–ˆ์„ ๊ฒฝ์šฐ์—๋„ ํด๋ผ์ด์–ธํŠธ๋‹จ์—์„œ access_token์„ ํš๋“ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ๋‚˜์š”?
README.MD ์—์„œ๋Š” signIn() ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด์„œ๋งŒ google User ๊ฐ์ฒด์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ ๋Š” ํ•˜์ง€๋งŒ.. getAuthCode๋ฅผ ํ†ตํ•ด ์„œ๋ฒ„์‚ฌ์ด๋“œ์—์„œ ์ธ์ฆํ•˜๋”๋ผ๋„ ํด๋ผ์ด์–ธํŠธ์—์„œ๋Š” window.gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse() (GoogleUser.getAuthResponse) ๋ฅผ ํ†ตํ•ด ์•ก์„ธ์Šคํ† ํฐ์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ์•Œ๊ณ ์žˆ์Šต๋‹ˆ๋‹ค.
๊ทธ๋ž˜์„œ ํ˜น์‹œ getAuthCode๋ฅผ ํ†ตํ•œ ์„œ๋ฒ„์‚ฌ์ด๋“œ ์ธ์ฆ์—์„œ๋„ access_token์ด๋‚˜ user profile์— ์ ‘๊ทผํ•˜๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ์ ‘๊ทผํ•ด์•ผ ํ•˜๋Š”์ง€ ์งˆ๋ฌธ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

๋งŒ์•ฝ ์œ„์— ๊ธฐ์ˆ ํ–ˆ๋“ฏ์ด ์ง์ ‘ window.gapi.auth2.getAuthInstance(์ดํ•˜์ƒ๋žต) ๋ฅผ ํ˜ธ์ถœํ•ด์„œ ์ ‘๊ทผํ•ด์•ผ ํ•œ๋‹ค๋ฉด, vue-google-oauth2 ์—์„œ๋„ ์ง์ ‘ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” API๊ฐ€ ์žˆ๋‹ค๋ฉด ์ข‹์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

๋ฐ”์˜์‹œ๊ฒ ์ง€๋งŒ ๋„์™€์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

How to use: getting email address?

Greetings and thank you for this project.

I was able to set it up, but I don't know how to actually use it: my backend server gets a token, what can I do with it? how can I fetch information, such as email, from it?

Thanks in advance

$gAuth type not supported

It seems $gAuth is not typed and remains as any.
ie: Property '$gAuth' does not exist on type 'MyComponent'.

image

getAuthResponse() never returns a refresh_token

Hi,

The function getAuthResponse() never returns a refresh_token.

I've added prompt: 'consent' to the config and I've removed the previously approved application from my Google account (because apparently the refresh_token is only issued on the first approval).

My code is as follows

import GAuth from 'vue-google-oauth2';
const configGAuth = {
    clientId: [CLIENT_ID],
    scope: 'https://www.googleapis.com/auth/drive.readonly',
    prompt: 'consent'
}
Vue.use(GAuth, configGAuth);

Then:

this.$gAuth.signIn()
.then(GoogleUser => {
    var authResult = GoogleUser.getAuthResponse();
})

This always returns:

access_token: "xxx"
expires_at: 1599153341490
expires_in: 3599
first_issued_at: 1599149742490
id_token: "xxx"
idpId: "google"
login_hint: "xxx"
scope: "email profile openid https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/drive.readonly"

I've even tried this on a brand new Google account and still the same. Is there a configuration option not in the docs? According to Google there's an 'access_type' option that needs to be 'offline' in order to be issued a refresh token but I don't see reference to this in the docs.

Can I only get authCode with out access token

When i use this.$gAuth.getAuthCode() function, I can get authCode but if I open network tab I can see also access_token and more info, I'm only want to get authCode without access_token, can I do this? Thank you!
Screen Shot 2020-12-14 at 10 35 54

How to make it so this work properly with Typescript?

I got rid of TS lint errors by doing this:

import GAuth from 'vue-google-oauth2'
import Vue from 'vue'
declare module 'vue/types/vue' {
  interface Vue {
    $gAuth: any
  }
}

But specifying it as any doesn't really enforce types. Can someone help me figure out to make $gAuth the correct type?

Cannot sign out

I log in fine.
I call signOut and then go to log in another user and I see I am logged in and can click on me and it does not even ask a password but puts me right in. This is a security breach.

I have looked and see there are 2 possible solutions, call the disconnect or call a revoke token.

IE Compatibility issue

I received a syntax error without any details in Internet explorer for this module. Chrome and Firefox are working fine.

Adding this module to new nuxt project causes "export" error

Describe the bug
I started a fresh Nuxt project - this project runs on my local machine with no issues. I followed your instructions to add this library as a Nuxt plugin - it compiles with no linting or compilation errors, but all I get in my browser is "Unexpected token 'export'"

To Reproduce
Steps to reproduce the behavior:

  1. Create a fresh Nuxt project using npx create-nuxt-app googleauth
  2. Confirm everything works on your local machine
  3. Add this library with npm install
  4. Create the plugin file as per instructions
  5. Add the plugin to nuxt.config.js as per instructions

Expected behavior
To work and be available to develop with

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser Chrome
  • Version Latest

Nuxt integration

How to integrate this with nuxt?

So far I added the plugin: /plugins/google.js

import Vue from 'vue'
import GAuth from 'vue-google-oauth2'

const clientId = 'my_client_id'

Vue.use(GAuth, { clientId })

And in nuxt.config.js:

  plugins: [
    { src: '@/plugins/google', ssr: false },
  ],

Nothing works...

$gAuth.isInit always return false

main.js

import GAuth from 'vue-google-oauth2'
const gauthOption = {
  clientId: 59xxxxxxxxxx-xxxxxxxxxxxxxxxxxxxx4u6k42sqsv49.apps.googleusercontent.com',
  scope: 'profile email',
  prompt: 'select_account'
}
Vue.use(GAuth,gauthOption)

View.vue

mounted() {
    let that = this;
    let checkGauthLoad = setInterval(function() {
      that.isInit = that.$gAuth.isInit;
      that.isSignIn = that.$gAuth.isAuthorized;
      if (that.isInit) clearInterval(checkGauthLoad);
    }, 5000);
  }

that.$gAuth.isInit is always false here

I wonder if this is the library's expected behavior. I couldn't find the information in the README.MD but my guess is that my app needs the oauth consent screen verified first by Google before I am able to use it. I am not so sure if it is the case here though.

What do you think the problem is?

Object is possibly 'null'

Describe the bug
Under TypeScript with "strictNullChecks": true environment (Nuxt.js default configuration), I got the following error and can't compile properly:

ERROR in .../node_modules/vue-google-oauth2/index.ts
153:7 Object is possibly 'null'.
    151 |     GoogleAuthConfig = Object.assign(GoogleAuthDefaultConfig, options);
    152 |     if (options.scope) {
  > 153 |       GoogleAuthConfig.scope = options.scope;
        |       ^
    154 |     }
    155 |     if (options.prompt) {
    156 |       prompt = options.prompt;

To Reproduce
Steps to reproduce the behavior:

  1. Set up Nuxt.js as a TypeScript project.
  2. Install this module (v1.4.0) and use it inside the project.
  3. Run npm run generate.
  4. You get the above error.

Expected behavior
Properly generate the static website using npm run generate.

Promise on this.$gAuth.signIn() never resolved

I am using the "Directly get back the access_token and id_token" in a Vue app, having the problem that the promise is never resolved. The account chooser opens, I select an account, after this no promise is resolved nor any other error to be found in the console.

This might not be related to your code since this a) has worked for me before and b) still is working on Safari!

this.$gAuth.signIn()
      .then(user => {
       // nor this, nor catch is being executed
       }).catch( (e) => {
          console.log("Auth error", e);
        });

I was hoping you have some suggestions of how to debug this and get to the source of it.

Edge Error: CustomError: Error in protected function: The window does not have an opener!

Describe the bug
Using this component to authenticate via Google. Works in Chrome, FireFox. Having issues with Edge.

With Edge, in the application click on Login. A separate window opens allowing me to either select my account or to provide credentials. After this, the window just says "One moment please...". In the console this error is outputted "CustomError: Error in protected function: The window does not have an opener!" There are no console messages in the original window (where the application is). This never goes away.

The correct URLs are setup in Google.

An odd behavior is that when testing on localhost (no https), the login works fine. This is happening in our integrated test environment where we do have https.

To Reproduce
Steps to reproduce the behavior:
See above.

Expected behavior
The google authentication window should be dismissed and proceed with the application flow.

Desktop (please complete the following information):

  • OS: Windows
  • Browser Edge
  • Version Microsoft Edge 42.17134.1098.0

Additional context
Component version 1.5.3
Vue 2.6.11

refresh token

Hey,

Is there anyway to get refresh token?

Thanks

Can't manage multiple instances

The package can't manage multiples instances of authorization => rights in the same app.

It could be nice to name the variable this.$gauth to manage multiples rights (scopes) when we ask for this.$gAuth.getAuthCode()

isInit never set to true due to idpiframe_initialization_failed error

$gAuth.isInit property is never set to true due to the following error being thrown by the module.

details: "Cookies are not enabled in current environment."
error: "idpiframe_initialization_failed"

image

Chrome then also displays the cookies blocked icon in the URL bar.

My configuration is as follows:

image

Any idea what could be causing this & how to resolve this?

vue-google-oauth2 on Vue3

Does anyone have an example of how to make vue-google-oauth2 work properly with Vue3 + Vuex + VueRouter?

Expected 1 argument, but got 0 in index.ts

Describe the bug
Typescript vue-cli compiler returns this error.

`ERROR in node_modules/vue-google-oauth2/index.ts(17,13):
17:13 Expected 1 arguments, but got 0. Did you forget to include 'void' in your type argument to 'Promise'?
15 | if (!script.readyState || /loaded|complete/.test(script.readyState)) {
16 | setTimeout(() => {

17 | resolve();
| ^
18 | }, 500);
19 | }
20 | };`

To Reproduce
Steps to reproduce the behavior:

  1. Update all npms using ncu -u
  2. Execute the serve command in vue-cli

Expected behavior
Expect vue-google-oauth2 to transpile properly.

"ERROR in build.js from UglifyJs"

Hey,
so when i tried to "npm run build" i come with this error:

 npm run build

> [email protected] build C:\wamp64\www\vue\xxx
> cross-env NODE_ENV=production webpack --progress --hide-modules

Hash: 84a6a8eca84724ecbfa8                                                              
Version: webpack 3.12.0
Time: 5615ms
       Asset     Size  Chunks                    Chunk Names
    build.js  1.19 MB       0  [emitted]  [big]  main
build.js.map  1.55 MB       0  [emitted]         main

ERROR in build.js from UglifyJs
Unexpected token: operator (>) [build.js:37030,34]
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: `cross-env NODE_ENV=production webpack --progress --hide-modules`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Elior\AppData\Roaming\npm-cache\_logs\2020-05-26T14_39_28_953Z-debug.log

So to understand why this is happen, i removed plugins from main.js
And find out unfortunately, that "vue-google-oauth2" causing this problem.

I have no idea how to solve it, i can provide any info needed..

isSignedIn state gone after 1 hour

Hey,

I'm currently trying to integrate your package into my Application. The authentication process of my SaaS-App is my own, so there is no Google Auth.

I just want to get permission to access the Google Calendar of my app users at the end of the day ๐Ÿ˜„

Right now i've implemented the Google "Sign-In" button via your package with the getAuthCode() method and i'm getting the one-time code from Google. Then the exchange is done on backend-side, to get refresh code and so on. So far so good.

The only problem i'm having now is that after 1 hour (lifetime of code/token) the state isSignedIn of the user is false.

The reason i need the state on frontend-side is, that i want to give the user the ability to "opt-out" from my service and revoke google permissions via disconnect() method. This works perfectly within 1 hour.

I wasn't able to find any example to achieve this. Can you help me?

Thanks!

Unexpected token 'export'

Describe the bug
SyntaxError: Unexpected token 'export' after nuxt app compiled

To Reproduce
Steps to reproduce the behavior:

  1. Install package and create a plugin: 'vue-google-oauth2.js'
  2. Include the plugin in nuxt.config.js
  3. Wait for nuxt app compile successfully
  4. Access nuxt app on browser

Expected behavior
Nuxt app running without error

Screenshots
image

**Desktop

  • OS: Mac OS
  • Browser: Chrome
  • Version: 85.0.4183.121

Missing required parameter 'client_id'

If I use clientId as a config parameter, I see the following error Missing required parameter 'client_id' in the console as a response to the Google load.

import Vue from 'vue'
import GoogleAuth from 'vue-google-oauth2'

Vue.use(GoogleAuth, {
  clientId: 'xxxx',
  scope: 'profile email'
})

Screenshot 2020-10-27 at 16 38 18

If I use client_id it works. Am I missing something?

Wont initalize

Code taken from the sample keeps looping because the it never gets initialized

I've added the localhost and correct port to the Authorized JavaScript origins and changed the client ID to be my own. It however keeps looping through this section of code

created() { let that = this; let checkGauthLoad = setInterval(function() { that.isInit = that.$gAuth.isInit; that.isSignIn = that.$gAuth.isAuthorized; if (that.isInit) clearInterval(checkGauthLoad); }, 1000); }

error in parent page "popup_closed_by_user"

Describe the bug
shown error, when the google sign-in popup closed

To Reproduce
Steps to reproduce the behavior:

  1. Go to Front-end Demo
  2. test sign-in
  3. google sign-in popup open, and complete google login, and popup close.
  4. See error in parent page
    error: "popup_closed_by_user" (cb=gapi.loaded_0 (268,25))

Desktop (please complete the following information):

  • OS: Window
  • Browser Edge

Not always, but sometimes this happens.

Scope to only 'email' is not effective in GAuth options?

Describe the bug
scope to only 'email' is not effective. It always seem to be overridden and asking for more?

To Reproduce
Steps to reproduce the behavior:

  1. Init with
    const gauthOption = {
    clientId: 'xxxxxx.apps.googleusercontent.com',
    scope: 'email',
    prompt: 'select_account'
    }
    Vue.use(GAuth, gauthOption)
  2. Popup will display
  3. Because the request sent has '&scope=openid%20profile%20email&'

Expected behavior
Ask only for the user email

Desktop (please complete the following information):

  • Ubuntu
  • Chrome

Wondering if it could be related to

Note: By default, the fetch_basic_profile parameter of gapi.auth2.init() is set to true, which will automatically add 'email profile openid' as scope.
https://developers.google.com/identity/sign-in/web/sign-in

Unable to get Refresh token

Here's the code I ran
const googleUser = await this.$gAuth.signIn()
console.log(googleUser.getAuthResponse())

The prompt has been set to 'consent'.
However, the Refresh token is not returned.
I know that the Refresh token is created only when the token is retrieved for the first time according to Google's specification.
Therefore, I have to revoke the token before retrieving it.

Expected behavior
We also want the Refresh token to be returned.

Screenshots
The contents of googleUser.getAuthResponse are as shown in the image.
ๅ็งฐๆœช่จญๅฎš3

Google+ API Shutdown

How will it be affected on google+ API shutdown set to start from March 7, 2019

Nuxt 'signIn' of undefined ($gAuth)

Im using Nuxt 2.14.12, but getting this error
image

Everything must be fine

Added Api code to get access token as pugin (~/plugins/googleAuth.js)

import Vue from 'vue'
import GAuth from 'vue-google-oauth2'
export const gauthOption = {
    clientId: "/key/",
    scope: 'profile email',
    prompt: 'select_account'
};
Vue.use(GAuth, gauthOption)

calling function

try {
    let user = await this.$gAuth.signIn();
} catch (e) {
    console.warn(e);
}

**Desktop

  • OS: Windows 10
  • Browser - Chrome last verion
  • Nuxt - 2.14
  • Vue 2.6 (I guess)

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.