前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Vue.js中Google第三方登录api实现[亲测可用]

Vue.js中Google第三方登录api实现[亲测可用]

原创
作者头像
芈渡
修改2020-06-08 10:49:21
5.8K5
修改2020-06-08 10:49:21
举报
文章被收录于专栏:我的代码世界我的代码世界

上一篇说了 facebook的实现,接下来说下google 的实现了,国际化的用的少.实际详细的文档也不多,这记录下来!

demo 地址请狠狠的戳这里  http://download.lllomh.com/cliect/#/product/J417101756893390

一:开发者平台配置

进入开发者平台 https://console.developers.google.com/apis/credentials?project=matest-247702

在凭据中创建app凭据:

设置 重定向地址等相关内容

动态演示:

我们需要的 是那个客户端 ID!

二:代码

核心代码:

代码语言:javascript
复制
<template>
 <div>
   <button v-google-signin-button="clientId" class="google-signin-button"> Continue with Google</button>
 </div>
</template>

<script>
  import GoogleSignInButton from 'vue-google-signin-button-directive'
  import jsonwebtoken from 'jsonwebtoken'
  export default {
    directives: {
      GoogleSignInButton
    },
    data: () => ({
      clientId: '345345-petbt7osm0gs9mtivclevt6cjb9la43b.apps.googleusercontent.com'
    }),
    mounted(){

    },
    methods: {
      OnGoogleAuthSuccess (idToken) {
        console.log(idToken,"tokesdasdasd") //返回第三方结果信息 默认是全token 要用jsonwebtoken 解析
        // Receive the idToken and make your magic with the backend
      },
      OnGoogleAuthFail (error) {
        console.log(error)
      }
    }
  }
</script>

<style>
  .google-signin-button {
    color: white;
    background-color: red;
    height: 50px;
    font-size: 16px;
    border-radius: 10px;
    padding: 10px 20px 25px 20px;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
  }
</style>

记得 npm install vue-google-signin-button-directive && npm install jsonwebtoken

结果如下:

比如这里 我的 url 是localhost:5000,那么开发者平台里面也要配置这个重定向地址=>

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一:开发者平台配置
  • 二:代码
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档