npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-oauth-cordova

v1.0.11

Published

Login facebok, google, instagram using web oauth provider, support cordova too.

Downloads

12

Readme

Vue Oauth Cordova

  • login with google, facebook, instagram using oauth provider
  • support cordova using inappbrowser, tested in ios android simulator
  • now just for testing and learning, not ready in production

Install

    yarn add vue-auth-cordova

for cordova, first install inappbrowser plugin cordova plugin add cordova-inappbrowser

Usage

  1. register vue plugin
        import oauth from 'vue-auth-cordova'
        //required parameter every platform `client_id, client_secret, redirect_uri`
        Vue.use(oauth, {
            clearCacheInappBrowserBeforeLogin: false, //only for cordova
            facebook: {
                client_id: process.env.FACEBOOK_CLIENT_ID,
                client_secret: process.env.FACEBOOK_CLIENT_SECRET,
                redirect_uri: process.env.FACEBOOK_REDIRECT_URI
            },
            google: {
                client_id: process.env.GOOGLE_CLIENT_ID,
                client_secret: process.env.GOOGLE_CLIENT_SECRET,
                redirect_uri: process.env.GOOGLE_REDIRECT_URI,
                scope: ['https://www.googleapis.com/auth/youtube.readonly']// add new scope
            },
            instagram: {
                client_id: process.env.IG_CLIENT_ID,
                client_secret: process.env.IG_CLIENT_SECRET,
                redirect_uri: process.env.IG_REDIRECT_URI
            }
        })
  2. using plugin
  • using oauth method
     // @click.prevent="$oauth.loginWith('facebook')"
     // @click.prevent="$oauth.loginWith('google')"
     // @click.prevent="$oauth.loginWith('instagram')"
  • login with facebook
        <q-btn label="Login with Facebook"
                 class="bg-facebook text-white full-width q-py-sm"
                 unelevated
                 no-caps
                 icon="img:statics/svg/nucleo/logo-facebook-glyph-32-tuatara.svg"
                 @click.prevent="$oauth.loginWith('facebook')" />
  • listen response
            mounted() {
                this.$oauth.bus.$on('OAUTH_RESPONSE', this.oauthResponse)
            },
            beforeDestroy() {
                this.$oauth.bus.$off('OAUTH_RESPONSE')
            },
            methods: {
                getUserProfile(val) {
                    switch (val.type) {
                        case 'google':
                        return { id: val.data.id, name: val.data.name, email: val.data.email, picture: val.data.picture, type: val.type }
                        case 'facebook':
                        return { id: val.data.id, name: val.data.name, email: val.data.email, picture: val.data.picture.data.url, type: val.type }
                        case 'instagram':
                        return { id: val.data.id, name: val.data.full_name, email: val.data.username, picture: val.data.profile_picture, type: val.type }
                    }
                },
                oauthResponse(val) {
                    console.log('OAUTH RESPONSE', val)
                    if (val.status === 'success') {
                        let data = this.getUserProfile(val)
                        this.$q.notify(`Success Login as ${data.name}`)
                        this.$router.replace({ path: '/verify-user', query: data })
                    } else {
                        this.$q.notify('Login Failed')
                    }
                }
            }
  • format response
    • format error

             {
                 "status": "error",
                 "type": "facebook",
                 "data": "",
                 "errorMessage": {
                     "error": {
                     "message": "Invalid OAuth access token.",
                     "type": "OAuthException",
                     "code": 190,
                     "fbtrace_id": "AmAUXDKkiDSAd73MS5fwpT3"
                     }
                 }
             }
    • format success

          {
              "status": "success",
              "type": "facebook",
              "data": {
                  "access_token":"xxxx"
                  "state":{
                      "type":"fb"
                      }
                  "id": "7490......",
                  "name": "John Do",
                  "email": "[email protected]"
              },
              "errorMessage": ""
          }
    • this plugin only return basic profile from oauth provider, if you want to get custom scope like youtube channel, the success response return acces_token, you can use it to fetch other scope manually, for now custom scope only for google.

      1. first add youtube scope in oauth parameter
          google: {
              client_id: process.env.GOOGLE_CLIENT_ID,
              client_secret: process.env.GOOGLE_CLIENT_SECRET,
              redirect_uri: process.env.GOOGLE_REDIRECT_URI,
              scope: ['https://www.googleapis.com/auth/youtube.readonly']
          },
      1. get youtube channel

            this.$oauth.bus.$on('OAUTH_RESPONSE', async (response) => {
                   try {
                        let getYoutubeDetail = await fetch(
                        `https://www.googleapis.com/youtube/v3/channels?mine=true&part=id,snippet&access_token=${accessToken}&key=YOUTUBE_API_KEY`,
                        {
                            referrer: 'http://localhost:8080/login',
                            referrerPolicy: 'unsafe-url'
                        }
                        )
                        let response = await getYoutubeDetail.json()
                        return response
                    } catch (e) {
                        return e
                    }
            })

        note: enable restrict key to prevent quota limit youtube v3

  1. how to switch account within cordova inappbrowser

    • facebook : the flow is logout facebook then login again with different account, add options value for facebook relogin

      this.$oauth.loginWith('fb', { relogin:true, token:'LOGIN ACCCES TOKEN' })
    • instagram : same with facebook add relogin parameter

      this.$oauth.loginWith('instagram', { relogin:true, token:'LOGIN ACCCES TOKEN' })
    • google : google oauth is automatically display prompt to switch another account

    • you can add state parameter to oauth options

      let options = { ...others, state: { redirect_to: redirectTo } }
      this.$oauth.loginWith(type, options)

      get state parameter from oauth response

      "data": {
          "access_token":"xxxx"
          "state":{
              "type":"facebook",
              "redirect_to": "http://localhost/connect"
              }