🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

vue3-google-oauth2

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue3-google-oauth2

Handling Google sign-in and sign-out for Vue3 applications.

1.0.7
latest
Source
npm
Version published
Weekly downloads
943
-7.37%
Maintainers
1
Weekly downloads
 
Created
Source

DEPRECATED - no longer actively maintained

You can use this plugin vue3-google-login instead to have support for the new Google Identity Services JavaScript library.

vue3-google-oauth2

Handling Google sign-in and sign-out for Vue3 applications.

Please refer to here for Vue2 applications.

npm bundle size GitHub vue3-google-oauth2

Front-end Demo

Installation

Installation with npm

npm install vue3-google-oauth2

Installation with yarn

yarn add vue3-google-oauth2

Initialization

import { createApp } from 'vue'
import App from './App.vue'
import GAuth from 'vue3-google-oauth2'
const app = createApp(App)

const gAuthOptions = { clientId: 'YOUR_CLIENT_ID', scope: 'email', prompt: 'consent', fetch_basic_profile: false }
app.use(GAuth, gAuthOptions)

Options

PropertyTypeRequiredDescription
clientIdStringRequired.The app's client ID, found and created in the Google Developers Console.
scopeStringOptional.Default value is profile email. Full list of scopes.
promptStringOptional.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_profileBooleanOptional.If set to true, email profile openid will be automatically added as scope. Default value is true.

Methods

PropertyDescriptionType
instancereturn of gapi.auth2.getAuthInstance()Object
signInfunction for sign-inFunction
getAuthCodefunction for getting authCodeFunction
signOutfunction for sign-outFunction

Reactivity

We support reactivity by Provide/Injection. Refer to sample project.

PropertyDescriptionType
Vue3GoogleOauth.isInitit will return reactivity object value({isInit, isAuthorized})Object
Vue3GoogleOauth.isAuthorizedit will return reactivity object value({isInit, isAuthorized})Object

Usages

Refer to sample project.

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.

Keywords

vue

FAQs

Package last updated on 17 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts