Vue.js中Google第三方登录api实现

Vue.js中Google第三方登录api实现

1.进入开发者平台 创建Google API控制台项目和客户端ID

https://console.developers.google.com/projectselector2/apis/library?pli=1&supportedpurview=project(地址)

在这里插入图片描述

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

在这里插入图片描述

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

在这里插入图片描述

OAuth 同意屏幕

在这里插入图片描述

画红色框的要与你使用到的网站的一致

开启api库

在这里插入图片描述

2.代码

<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' //客户端id
    }),
    mounted(){
 
    },
    methods: {
      OnGoogleAuthSuccess (idToken) {
        console.log(idToken,"tokesdasdasd") //返回第三方结果信息 默认是全token 要用jsonwebtoken 解析
        // Receive the idToken and make your magic with the backend
        const jsondate = jsonwebtoken.decode(idToken);//解析idToken
      },
      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

在这里插入图片描述

参考文档
https://blog.csdn.net/lllomh/article/details/97258715

https://www.cnblogs.com/lngg057/p/5020192.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值